How to merge data sets with a common variable?
Here is the simple way of merging the data sets with a common variable if the datasets has the same prefix name.
For example: col1-col10, dsn1-dsn 7 , or data1 to data10 with common variable of ID.
Considering we have 10 datsets and all of them having the same prefix data;
%macro mymerge (n);
data merged;
merge %do i = 1 % to &n;
data&i %end; ; /* this additional ';' is necessary, the first ';' is for the "%end", while the second ';' is for "Merge"*/;
by id;
run;
%mend;
%mymerge(10)
For example: col1-col10, dsn1-dsn 7 , or data1 to data10 with common variable of ID.
Considering we have 10 datsets and all of them having the same prefix data;
%macro mymerge (n);
data merged;
merge %do i = 1 % to &n;
data&i %end; ; /* this additional ';' is necessary, the first ';' is for the "%end", while the second ';' is for "Merge"*/;
by id;
run;
%mend;
%mymerge(10)
Comments
Post a Comment