动态删除列,语法没有变化

问题描述 投票:0回答:1

我想在 SPSS 中运行一系列要求输入变量具有一定方差的算法。我希望能够在 SPSS 中动态选择具有正则表达式且方差不等于 0 的变量。我经常使用

spssinc select variables
和正则表达式来定义变量列表。有没有办法将其扩展到仅选择方差不等于零的变量?

下面是一个示例数据集。正如您所看到的,名为 Test_price01 的列的方差为 0。是否可以从数据集中删除此列(或者是否有其他方法不选择此列?)?

data list list/ID (A3) Sex (A1) Age (F2.0) Education (A5) Test_price01 Test_new01 Test_income01 Test_exp01 Test_01 Test_house01 Test_car01 Test_boat01 Test_var01 Test_var02 .
begin data
    ID1 M 20 Prim 1 2 3 4 5 6 7 8 9 9
    ID2 F 22 High 1 4 3 6 3 8 1 2 5 8
    ID3 M 30 High 1 8 6 4 2 1 3 5 7 9
end data.
dataset name survey.

下面是我通常动态选择变量的方式

spssinc select variables macroname="!Test_Vars" /properties pattern=".*Test_".
spss
1个回答
0
投票

我不知道在 SPSS 中执行此操作的直接方法,但以下语法为您提供了一种根据分析结果自动创建语法的方法 - 您通过

OMS
功能从输出中捕获结果,然后创建一个基于结果的新语法,然后运行它:

* this is your example with a couple of zero variance variables added.
data list list/ID (A3) Sex (A1) Age (F2.0) Education (A5) Test_price01 Test_new01 Test_income01 Test_exp01 Test_01 Test_house01 Test_car01 Test_boat01 Test_var01 Test_var02 .
begin data
    ID1 M 20 Prim 1 2 3 4 5 6 7 8 9 9
    ID2 F 22  High 1 4 3 6 3 8 7 2 9 8
    ID3 M 30 High 1 8 6 4 2 1 7 5 9 9
end data.
dataset name survey.

DATASET DECLARE  stds.
OMS  /SELECT TABLES
  /IF COMMANDS=['Descriptives'] SUBTYPES=['Descriptive Statistics']
  /DESTINATION FORMAT=SAV  OUTFILE='stds' .
desc Test_price01 to Test_var02.
omsend.

dataset activate stds.
select if Std.Deviation=0.
write out="yourpath\del vars.sps"/"delete variables ", Var1, "." .
exe.

dataset activate survey.
insert file="yourpath\del vars.sps".
© www.soinside.com 2019 - 2024. All rights reserved.