Cornell University Cornell University CISER

CISER Computing

Using the WHERE Statement to Subset Data

Use a WHERE statement to select observations that meet a particular condition from a SAS data set. The WHERE statement subsets the input data by specifying certain conditions that each observation must meet before it is available for processing. The conditions that you define in a WHERE statement is an arithemtic or logical expression that generally consists of a sequence of operands and operators. To compare character values, you must enclose them in single or double quotation marks and the values must match exactly, including capitalization. Using the WHERE statement might improve the efficiency of your SAS programs because SAS is not required to read all the observations in the input data set. Note: You can use only one WHERE statement in a Data or a Proc step. Examples are given below.

 

/* Selecting observations in a Data Step */

libname ssd 'u:\' ;
data subset;
    set ssd.all ;
    where age <= 65 and  upcase(gender) = "M" ;
run;

/* Selecting observations for processing in a Proc Step */

proc means data=ssd.all;
    where age <= 65 and  upcase(gender) = "M" ;
run;