Nested DO IF Structures (DO IF command)
To perform transformations involving logical tests
on two variables, you can use nested DO IF—END
IF
structures.
- There must be an
END IF
command for everyDO IF
command in the structure.
Example
DO IF (Ethnicity EQ 5). /*Do whites
+ DO IF (Gender EQ 2). /*White female
+ COMPUTE Gender_Ethnicity=3.
+ ELSE. /*White male
+ COMPUTE Gender_Ethnicity=1.
+ END IF. /*Whites done
ELSE IF (Gender EQ 2). /*Nonwhite female
COMPUTE Gender_Ethnicity=4.
ELSE. /*Nonwhite male
COMPUTE Gender_Ethnicity=2.
END IF. /*Nonwhites done
- This structure creates variable Gender_Ethnicity, which indicates both the sex and minority status of an individual.
- An optional plus sign, minus sign, or period in the first column allows you to indent commands so you can easily see the nested structures.