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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 677 views
  • 0 likes
  • 2 in conversation