我想基于同一变量的值标签来更新该变量的某些值:
使用伪代码:
for V in var1 to var10:
if value label of V is 'x':
set value 99
答案 0 :(得分:1)
首先,我们将创建一些虚假数据进行演示:
data list list/a1 to a3 (3f1) notforuse (f1).
begin data
1,2,2,55
2,1,4,66
3,4,1,77
end data.
value labels
a1 1 'x1' 2 'x' 3 'x3'
/a2 1 'y1' 2 'a' 3 'b' 4 'x'
/a3 1 'n' 2 'x'
/notforuse 55 'nn' 66 "x".
现在是实际任务:
* first step is to create a list of variable labels.
dataset name origdata.
DATASET DECLARE vallabs.
OMS /SELECT TABLES /IF COMMANDS=['File Information'] SUBTYPES=['Variable Values']
/DESTINATION FORMAT=SAV OUTFILE='vallabs' VIEWER=NO.
DISPLAY DICTIONARY.
OMSEND.
dataset activate vallabs.
* you now have a full list of your actual variable labels. next step is to select the variables you want to work on, and the labels you want to work on.
*to select the relevant variables.
select if any(var1 , "a1", "a2", "a3").
* can alternatively use the following: .
select if char.index(var1, "a")>0.
*to set the new values for relevant labels:.
recode label ("x"=99)("y1"=999) into newval.
select if not missing(newval).
*now use the list to create a new syntax: .
cd 'yourpath\writeable directory'
write out='val lab syntax.sps' /"if ", var1, " = ", var2, " ", var1, " = ", newval, ".".
exe.
*now use the new syntax in the original data:.
dataset activate origdata.
insert file= 'val lab syntax.sps'.
exe.