Hi everyone!
I was trying to shorten my Syntax a little by using loops. However, when I tried, SPSS gave me an error warning.
This is the code that works:
compute v1_agg = 0.
if (any(1, v1_a to v1z)) v1_agg = 1.
if (any(2, v1_a to v1z)) v1_agg = 2.
if (any(3, v1_a to v1z)) v1_agg = 3.
if (any(4, v1_a to v1z)) v1_agg = 4.
recode v1_agg (0=sysmis).
EXECUTE.
delete variables v1_a to v1_z.
EXECUTE.
This is the code with the loop, that didn't work:
compute v1_agg = 0.
loop #i 1 to 4.
if (any(#i, v1_a to v1_z)) v1_agg = #i.
end loop.
recode v1_agg (0=sysmis).
EXECUTE.
delete variables v1_a to v1_z.
EXECUTE.
To me it seemed pretty straight forward to substitute the digits in my code with the index variable of a loop, but it didn't work. Instead I got this error message:
(translating this from German into English so it might be slightly different)
error 4840 in column 6. text: #i
the command LOOP can include two optional clauses - one index clause in the form "variable = expression TO expression BY expression" and one conditional clause in the form of an if clause. The text found does not match either of the two forms.
I assume you can't use the index variable as a placeholder for integers like that, but I am a little confused as to what is possible and what not or if I just made a different mistake altogether.
I appreciate any help or tip :)
best,
Christoph
------------------------------
Christoph Kulicke
------------------------------
#SPSSStatistics