Subsetting Data

As you read your data, you can subset it by processing only those observations that meet a specified condition. To do this, you can use a subsetting IF statement in any DATA step.

Using a Subsetting IF Statement

The subsetting IF statement causes the DATA step to continue processing only those observations that meet the condition of the expression specified in the IF statement. The resulting SAS data set or data sets contain a subset of the original external file or SAS data set.
Syntax, subsetting IF statement:
IF expression;
expression is any valid SAS expression.
  • If the expression is true, the DATA step continues to process that observation.
  • If the expression is false, no further statements are processed for that observation, and control returns to the top of the DATA step.

Example: Subsetting IF Statement

The subsetting IF statement below selects only observations whose values for Tolerance are D. It is positioned in the DATA step for efficiency: other statements do not need to process unwanted observations.
data sasuser.stress;
   infile tests; 
   input ID $ 1-4 Name $ 6-25 RestHR 27-29 MaxHR 31-33 
         RecHR 35-37 TimeMin 39-40 TimeSec 42-43 
         Tolerance $ 45; 
   if tolerance='D'; 
   TotalTime=(timemin*60)+timesec; 
run;
Because Tolerance is a character variable, the value D must be enclosed in quotation marks, and it must be the same case as in the data set.
Last updated: January 10, 2018
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.144.65