Processing Selected SAS Data Set Observations Using WHERE Statements in Procedures - SAS Programming

When you only need to process a subset of an existing SAS data set, use a WHERE statement in the procedure to subset your data set rather than creating a new reduced data set and then running the procedure.For example:

Example– INEFFICIENT

DATA SUBSET;
SET OLD;
WHERE GROUP='A'; /* WHERE statement in the DATA step */
RUN;
PROC UNIVARIATE DATA*SUBSET;
VAR X Y Z;
RUN;

Why create that extra SAS data set SUBSET? It is much more efficient to instruct the procedure to operate on only the observations in the original data set OLD that meet the selection criteria,as follows:

Example – EFFICIENT

PROC UNIVARIATE DATA=OLD;
WHERE GROUP='A'; /* WHERE statement in the PROC step */
VAR X Y Z;
RON;

Of course, if you want to run PROC UNIVARIATE for each value of GROUP,it is better to pre-sort data set OLD by GROUP (using PROC SORT),and then use GROUP as a BY variable in the procedure.Also, if you plan to run several procedures on the same subset, you are probably better off storing the subset as a SAS data set and then running the procedures .


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAS Programming Topics