« SAS extract sentence when 2 string match conditions exist | Main | Backfired advertising campgaign - suspicious packages »

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:

  1. The first observation on dataset XX is read in, and the value of X is 1.
  2. 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.
  3. The merged observation is written out.
  4. The second observation from dataset XX is read in, and the value of X is 2.
  5. 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.
  6. Same thing happens with the third observation from dataset XX.

 

Many thanks to the contributors on the SAS Google Group for this lesson. 

Posted on Saturday, May 24, 2008 by Registered CommenterJared in | CommentsPost a Comment

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>