Yishoov
Yishoov

Reputation: 11

DO IF, ELSE: Else not being computed

Only the initial if statement variable computation is being completed--the ELSE part is being ignored. Can someone explain why? Many thanks.

DATASET ACTIVATE DataSet1.
DO IF ((A1_SCN2_PR1_UE = 0 & A1_SCN3_PR1_UE = 0 & A1_SCN4_PR1_UE = 0 & A1_SCN5_PR1_UE = 0) | 
       (A2_SCN2_PR1_UE = 0 & A2_SCN3_PR1_UE = 0 & A2_SCN4_PR1_UE = 0 & A2_SCN5_PR1_UE = 0) | 
       (A3_SCN2_PR1_UE = 0 & A3_SCN3_PR1_UE = 0 & A3_SCN4_PR1_UE = 0 & A3_SCN5_PR1_UE = 0)).
Compute FM_zero = 1.
ELSE.
Compute FM_zero = 0.
End IF.
EXECUTE.

Upvotes: 1

Views: 141

Answers (2)

JKP
JKP

Reputation: 5417

SPSS uses three-valued logic: True, False, or don't know (sysmis). From the Syntax Reference Manual... Missing values returned by the logical expression on DO IF or on any ELSE IF cause control to pass to the END IF command at that point.

So generally you should put the sysmis test first in your DO IF and follow with appropriate ELSE IF/ELSE.

Upvotes: 1

eli-k
eli-k

Reputation: 11310

Not sure why your ELSE is not being computed, but I suggest you drop the DO IF and go this way instead:

compute FM_zero = 
    ((A1_SCN2_PR1_UE = 0 & A1_SCN3_PR1_UE = 0 & A1_SCN4_PR1_UE = 0 & A1_SCN5_PR1_UE = 0) | 
    (A2_SCN2_PR1_UE = 0 & A2_SCN3_PR1_UE = 0 & A2_SCN4_PR1_UE = 0 & A2_SCN5_PR1_UE = 0) | 
    (A3_SCN2_PR1_UE = 0 & A3_SCN3_PR1_UE = 0 & A3_SCN4_PR1_UE = 0 & A3_SCN5_PR1_UE = 0)).

This will put a 1 in all true cases and 0 in all false cases.

Upvotes: 1

Related Questions