Hi,
I have two datasets with identical variables (Dataset2 is an updated version of Dataset1). Each dataset is unique at the person level and contains ID and about 20 categorical variables. Only a subset of those in Dataset1 are in Dataset2--that is, if any person in Dataset1's information had changed, it would be reflected in Dataset2, but if their information stayed the same, they would not have a record in Dataset2:
Dataset1:
ID categ_var1 categ_var2...etc
1 a d
2 a g
3 b d
4 c e
5 b f
Dataset2:
ID categ_var1 categ_var2...etc
2 a b
5 c f
What I want is to combine the two datasets such that I have one record for each person, but if they have a record in Dataset2, SAS keeps that record instead of the one from Dataset1:
ID categ_var1 categ_var2...etc
1 a d
2 a b
3 b d
4 c e
5 c f
Any help is much appreciated.
I think you may want something like:
data want;
update dataset1 dataset2;
by id; /* each of the source datasets should be sorted by id if they aren't already*/
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!
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.