Using Conditional Expressions
You can use conditional expressions (also called logical expressions) to apply transformations to selected subsets of cases. A conditional expression returns a value of true, false, or missing for each case. If the result of a conditional expression is true, the transformation is applied to that case. If the result is false or missing, the transformation is not applied to the case.
To specify a conditional expression:
- Click If in the Compute Variable dialog box. This opens the If Cases dialog box.
- Select Include if case satisfies condition.
- Enter the conditional expression.
Most conditional expressions contain at least one relational operator, as in:
age>=21
or
income*3<100
In the first example, only cases with a value of 21 or greater for Age [age] are selected. In the second example, Household income in thousands [income] multiplied by 3 must be less than 100 for a case to be selected.
You can also link two or more conditional expressions using logical operators, as in:
age>=21 | ed>=4
or
income*3<100 & ed=5
In the first example, cases that meet either the Age [age] condition or the Level of education [ed] condition are selected. In the second example, both the Household income in thousands [income] and Level of education [ed] conditions must be met for a case to be selected.