An Interesting Lesson Merging SAS Datasets
Take the following Dataset Merge example:
Data xx ; id=1; input x @@ ; datalines ;
1 2 3
;
run ;
Data yy ; id=1 ; x = 9; y=9 ; output; run;
proc sort data=xx; by id ; run ;
proc sort data=yy; by id; run;
Data merged; merge xx yy ; by id; run;
proc print; run;
What happens is this:
- The first observation on dataset XX is read in, and the value of X is 1.
- The first observation on dataset YY is read in. The value of X is 9, and it overlays the value read in from dataset XX.
- The merged observation is written out.
- The second observation from dataset XX is read in, and the value of X is 2.
- Since the ID values still match, no attempt is made to read another observation from dataset YY, the value of X does not change, and the merged result is written out.
- Same thing happens with the third observation from dataset XX.
Many thanks to the contributors on the SAS Google Group for this lesson.


Reader Comments