Return to Snippet

Revision: 5739
at March 31, 2008 14:12 by webonomic


Initial Code
/*Have 2 datasets*/
data table1;
INPUT id sex $ age;
DATALINES;
1 F 35
2 M 50
3 F 45
3 M 24
3 F 52
1 M 44
2 F 34
1 M 40
3 F 47
2 M 35
;
run;

data table2;
INPUT id name $;
DATALINES;
1 A
2 B
3 C
;
run; 

/*create Macro*/
%MACRO domerge(ds1=, ds2=, resultdataset=);

proc sort data=&ds1;
by id;
run;

proc sort data=&ds2;
by id;
run;

data &resultdataset;
merge &ds1 &ds2;
by id;
run;

%MEND domerge; 

/*Use the macro*/
%let t1 = table1;
%let t2 = table2;

%MACRO domerge(ds1=, ds2=, resultdataset=);

proc sort data=&ds1;
by id;
run;

proc sort data=&ds2;
by id;
run;

data &resultdataset;
merge &ds1 &ds2;
by id;
run;

%MEND domerge;

Initial URL
http://jaredprins.squarespace.com/blog/2008/3/31/reusable-data-merge-macro.html

Initial Description


Initial Title
Reusable Data Merge Macro

Initial Tags
data

Initial Language
SAS