Subsetting observations
Example: Create a subset of the SURVEY12 data set that is only the males.
Recall that the original data set looks like this:
SUBJ GENDER HEIGHT WEIGHT YEAR 1 M 68 155 91 7 F 72 205 90 9 M 66 120 93 5 F 63 102 92 8 M 70 250 91
In the data step, the statement that conditionally includes observations in an output data file is the subsetting IF statement. For instance:
Data Males; Set library.Survey12; IF Gender='M'; Proc Print; ID Subj; Title 'Like Example 1 in C&P Chapter 3'; run;
The Proc Print output indicates this worked fine:
Like Example 1 in C&P Chapter 3 SUBJ GENDER HEIGHT WEIGHT YEAR 1 M 68 155 91 9 M 66 120 93 8 M 250 70 91
Note that the subsetting IF statement is a special form of the IF statement that does not use THEN.
Subsetting IF statement (data step only)
|
The subsetting IF statement acts like a gate. In the normal flow of execution, each SAS statement in the data step is executed in turn. When the subsetting IF statement is encountered, expression is evaluated. One of two things occur: