* input the 1st data file ;
DATA first;
LENGTH CINFO $ 13;
INPUT CINFO $ ab ;
CARDS;
a220910308733 2
a220910308733 1
a220910176385 3
a220910367313 2
;
RUN;
* input the 2nd data file ;
DATA second;
LENGTH CINFO $ 13;
INPUT CINFO $ clitype ;
CARDS;
a220910308733 1
a220910308733 1
a220910367313 1
a220910282897 1
a220910250873 1
;
RUN;
* 1. sort "first" on CINFO and save the sorted file as "first_s" ;
PROC SORT DATA=first OUT=first_s;
BY CINFO;
RUN;
* 2. sort "second" on CINFO and save the sorted file as "second_s" ;
PROC SORT DATA=second OUT=second_s;
BY CINFO;
RUN;
* 3. merge "first_s" and "second_s" based on CINFO, creating "final" ;
DATA final;
MERGE first_s second_s;
BY CINFO;
RUN;
* Let's do a PROC PRINT of "final" to see if the merge worked ;
PROC PRINT DATA=final;
RUN;
输出是:
The SAS System 14:40 Wednesday, December 15, 2009 3