I have two data sets WORK and SUMS. WORK is my working data set and SUMS is half the size and contains the same exact IDs as WORK. SUMS has the variables I want for the observations I was analyzing, so I want to merge the data sets and replace the observations in WORK with those in SUMS.
Example of a small portion what they look like:
WORK
| SEQN | alcohol | legumes | meat |
| 10001 | 1.5 | 3.0 | 2.3 |
| 10002 | 1.4 | 2.3 | 3.5 |
| 10003 | 0 | 5.0 | 2.3 |
| 10004 | 3.0 | 2.0 | 2.0 |
SUMS
| SEQN | alcohol | legumes | meat |
| 10002 | 2.2 | 3.3 | 5.0 |
| 10004 | 5.5 | 3.8 | 2.2 |
So the observations in the SUMS would replace the existing ones in WORK.
Thanks for your time!
A straight merge will do this if the variable names are the same as in your example.
data want;
merge work sums;
by SEQN;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.