SAS-Efficient Coding Techniques-1:Reduction of Steps

REDUCE DATA STEPS



I have two data steps, in the first step I subset a data and in the next step I sort the data.
DATA ABC;
SET XYZ;
WHERE VAR1="VAR_VALUE";
KEEP VAR1 VAR2 VAR3;
RUN;


PROC SORT
DATA=ABC;
BY VAR2;
RUN;
Can we reduce these steps? Can we possibly reduce this to one..? One method would be to use keep and where statement with Sort statement Data.

PROC SORT
DATA=XYZ(KEEP=VAR1 VAR2 VAR3 WHERE=(VAR1="VAR1_VALUE")) OUT=ABC;
BY VAR2;
RUN;


And the other would be to use ‘Proc SQL’.Order by in the end does the sorting

PROC SQL;
CREATE TABLE ABC AS
SELECT VAR1,VAR2,VAR3
FROM XYZ
WHERE VAR1="VAR1_vALUE"
ORDER BY VAR2
;

quit;

Blog Widget by LinkWithin

Search this blog..

Loading