The SAS Output Delivery System and reporting techniques

Match-merging

Reply
New Contributor
Posts: 2

Match-merging

I have a question on match-merging. Can someone pls help, or direct me to where I can find a forum dedicated to base sas topics?

I don't understand why the 2nd obs in the output shows 32 for age. Shouldn't values from xx OVERWRITE values in yy when the BY variable matches? I expected age to be 23. My merge statement says: merge yy xx;

----------
data xx;
infile cards;
input name $ age $ height;
cards;
Adam 23 160

;
run;
data yy;
infile cards dsd dlm=' ';
input name $ age $ weight;
cards;
Adam 200
Adam 32 180
;
run;

data merge_yyxx;
merge yy xx;
by name;
run;

proc print data=merge_yyxx;
run;
-------
Output:

Obs name age weight height

1 Adam 23 200 160
2 Adam 32 180 160
Occasional Contributor
Posts: 10

Re: Match-merging

When merging your data the SAS matched the first observation from your first data set to teh first observation of your second data set. On the second pass you dont get a match, but rather you get the values retain from the first match and any the values from the second observaton of your first data set overwrite and liked named vars values.

If you want a good paper that covers this in detail I suggest you read:
http://dc-sug.org/merge.pdf Robert does an outstanding job at showing just the this case and many more.
New Contributor
Posts: 2

Re: Match-merging

Thanks!! The paper you suggested is great. It brought to light a number of problems and caveats. Thanks again.
Ask a Question
Discussion stats
  • 2 replies
  • 130 views
  • 0 likes
  • 2 in conversation