Continues processing only those observations that meet the condition of the specified expression.
| Valid in: | DATA step |
|---|---|
| Categories: | Action |
| CAS | |
| Type: | Executable |
| Note: | Using a random number function in a WHERE statement might generate a different result set from using a random number function in a subsetting IF statement. This difference can be caused by how the criteria are optimized internally by SAS and is expected behavior. |
Table of Contents
The subsetting IF statement causes the DATA step to continue processing only those raw data records or those observations from a SAS data set that meet the condition of the expression that is specified in the IF statement. If the expression is true for the observation (its value is neither 0 nor missing), SAS continues to execute the DATA step and includes the observation in the output data set. The resulting SAS data set or data sets contain a subset of the original external file or SAS data set.
If the expression is false (its value is 0 or missing), no further statements are processed for that observation or record, the current observation is not written to the data set, and the remaining program statements in the DATA step are not executed. SAS immediately returns to the beginning of the DATA step because the subsetting IF statement does not require additional statements to stop processing observations.
The LIKE operator in a WHERE clause matches patterns in words. To get the equivalent result in an IF statement, the '=:' operator can be used. This matches patterns that occur at the beginning of a string. Here is an example.
data test;
input name $;
datalines;
John
Diana
Diane
Sally
Doug
David
;
run;
data test;
set test;
if name =: 'D';
run;
proc print;
run;
The CONTAINS operator in a WHERE clause checks for a character string within a value. To get the equivalent result in an IF statement, the INDEX function can be used. For example:
data test;
set test;
if index(name,'ian') ge 1;
run;
proc print;
run;
if not (expression)
then delete;
F for
the variable SEX:
if sex='F';
if age;