Michael
Michael

Reputation: 133

SPSS syntax IF statement -> Multiple recode commands

I am trying to recode multiple variables with one IF statement. SPSS however does not like me doing so (I am probably missing something in the syntax, but I do not know what).

Example syntax:

IF (Var1=X) Var2=1 Var3=2 Var4=1.
Execute.

So I want SPSS to change variable 1, 2 and three if Var1=X. If I write the syntax like the example I get the error: The expression ends unexpectedly (at the start of the Var3=2 recode).

So my question is: how should I write the syntax to get SPSS to recode multiple variables with one IF statement?

Upvotes: 3

Views: 13985

Answers (1)

Jignesh Sutar
Jignesh Sutar

Reputation: 2929

Look up DO IF statement and the distinction between that and a IF statement, to better understand how each operates and help aid answer your question.

* Assuming Var1 is a string else just enter a numeric without quotes .
DO IF (Var1="X").
    COMPUTE Var2=1
    COMPUTE Var3=2
    COMPUTE Var4=1.
END IF.

Upvotes: 3

Related Questions