SPSS 查找并用数字变量替换语法?

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

我的数据集中的某些变量具有包含(Void)的值标签。例如:

变量名称:汽车数量

价值观:
0
1
2
3个或以上(无效)

我可以使用某种语法来执行相同的任务吗?或者,SPSS中有没有一种方法可以一次性删除所有(Void)?

当我单击/突出显示“值”列和“查找/替换”时,我可以手动将 (Void) 替换为 [空],以仅清除 (Void) 并保持其余标签不变。我必须根据包含该短语的变量数量多次单击此按钮。我似乎没有选择单击一次并重复它,直到在任何变量的值中不再找到该短语为止。

我还尝试了用于文本变量的语法版本,但无济于事:

do repeat vr=yourfirstvar to yourlastvar.  
compute vr=replace(vr, "na", "").  
end repeat.
spss
1个回答
0
投票

无法直接从语法中搜索和替换值标签。作为解决方法,以下语法创建一个包含值标签表的数据集。现在我们可以搜索和替换,然后自动创建一个新语法,将更正后的值标签附加回原始值:

首先创建一个带有值标签的示例数据集:

data list free/aa bb cc (3f1).
begin data
    1 2 3     2 4 5     6 2 1
end data.
value labels 
    aa
    1 "hello"
    2 "bye(Void)"
    3 "here"
    /bb
    1 "aba(Void)"
    2 "ima"
    /cc
    6 "here"
    7 "there"
    8 "(Void)in between".
dataset name orig.

现在给出解决方案:

* sending value labels to the output and capturing them through OMS.
DATASET DECLARE  vals.
OMS /SELECT TABLES /IF COMMANDS=['File Information'] SUBTYPES=['Variable Values'] 
    /DESTINATION FORMAT=SAV OUTFILE='vals'.
display dictionary.
omsend.
dataset activate vals.

* Now we create a syntax to change the labels and correct them. 
string cmd(a50).
compute cmd=concat("add value labels ",var1, " ", string(var2,f2), ' "', replace(label, "(Void)", ""), '".').
write out="c:\users\eli\remove void.sps" /cmd.
exe.

* the syntax is created, we go back to the original data and insert it.
dataset activate orig.
insert file="c:\users\eli\remove void.sps".
© www.soinside.com 2019 - 2024. All rights reserved.