Making Your Sorts More Efficient: Sort Only What You Have to Sort - SAS Programming

Drop variables and subset observations as part of your PROC SORT code rather than sorting first and then dropping and subsetting. In this example you want to create data set NEW as a sorted subset of data set OLD. You only want to keep selected observations and variables. Here is the inefficient method:

Example – INEFFICIENT

PROC SORT DATA=OLD;
BY ID DATE;
RUN;
DATA NEW;
SET OLD(DROP=X1-X10);
WHERE YEAR BETWEEN 'OlJAN90'D AND '3lDEC93'D;
RUN;

Here you sort the entire data set OLD,then create data set NEW by setting a selected part of OLD.There is no need to sort all of OLD.Here is the better way:

Example– EFFICIENT

PROC SORT DATA=OLD(DROP=X1-X10) OUT=NEW;
BY ID DATE;
WHERE YEAR BETWEEN '01JAN90'D AND '31DEC93'D;
RUN;

In the efficient example, you only sort those observations which meet the WHERE condition.In addition, you do not carry along any extra "baggage" by including the variables X1-X10,only to drop them later.The difference between these two programs, depending on how large a subset you are extracting and how many variables you are dropping, can be ENORMOUS!


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

SAS Programming Topics