Pages

Wednesday, July 31, 2013

Widgets

Merging Datasets faster

When merging two SAS data sets, many of us use one of these two methods
to keep only the observations where both input data sets contribute:

data test1;
merge step1(in=a)
step2(in=b);
by district studentid;
if a=1 and b=1;
run;
or
data test1;
merge step1(in=a)
step2(in=b);
by district studentid;
if a and b;
run;

This method executes faster (and saves a few keystrokes):
data test1;
merge step1(in=a)
step2(in=b);
by district studentid;
if a*b;
run;

This shortened version of the IF statement works since if either the variable
a or b is false, the expression resolves to zero (false).

No comments:

Post a Comment