SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Reading and Concatenating SAS Data Sets
Selecting Observations


In the previous practice, you created a data set identical to Stress2. But you usually don't want an exact duplicate of the existing data set.

For example, suppose you want to process only observations where the value for maximum heart rate (MaxHR) is less than 155 or where the value for resting heart rate (RestHR) is less than 71.

To select only those observations that meet a specified condition, you can use a subsetting IF statement in any DATA step.


General form, subsetting IF statement:
IF expression;  

where expression is any valid SAS expression.

  • If the expression is true for the observation, the current observation is written to the output data set.

  • If the expression is false, no further statements are processed for that record and the record is not written to the output SAS data set.


For example, the subsetting IF statement below selects only observations whose values for Placebo are YES.

     data lab23.drug1h;
        set research.cltrials;
        if placebo='YES';
     run; 
Because the variable Placebo is a character variable, the value YES must be enclosed in quotation marks and be the same case as in the data set.


back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement