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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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