Wednesday, October 18, 2006

Merging Data Sets 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).

2 Comments:

At 7:20 AM, Anonymous Anonymous said...

This is great. Thanks, Linda.

 
At 3:38 PM, Anonymous Anonymous said...

just tested with million level pseduo data set, no practical difference.

 

Post a Comment

<< Home