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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.