Sunday, March 4, 2012

Merging in SAS

For merging two data sets, we must sort the two data sets by a common variable.
let us consider the two data sets as data1, data2 and the common variable as id.Then after the processing in the data step , we can sort the two sets of data in the procedure step as follows.

proc sort data= mylib.data1;
by id;
run;

proc sort data= mylib.data2;
by id;
run;

After sorting the two data sets we can check whether they are sorted or not by the following procedure step

proc contents data=mylib.data1
run;

proc contents data=mylib.data1
run;

After sorting , we can merge the two data sets as follows

data mylib mdata;
merge mylib.data1 mylib.data2;
by id;
run;

proc print data =mylib.mdata;
run;


 

No comments:

Post a Comment