BookmarkSubscribeRSS Feed
base_SAS
Calcite | Level 5
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
2 REPLIES 2
TobyDunn_hotmail_com
Fluorite | Level 6
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.
base_SAS
Calcite | Level 5
Thanks!! The paper you suggested is great. It brought to light a number of problems and caveats. Thanks again.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 839 views
  • 0 likes
  • 2 in conversation