I was wondering if anyone could share how to merge two data sets conditionally. The following is a simplified example of what I am trying to do. I have two data sets and each is unique at the individ_id_num and year level. The year variable ranges from 2000-2020. I only want the merge to occur for year=2018. Is there some way to specify merge only if year=2018 in both data sets?
data want;
merge have1(where=(year=2018) in=in1) have2(where=(year=2018) in=in2);
by indiv_id_num;
if in1 and in2;
run;
Assumes have1 and have2 are properly sorted by indiv_id_num.
data want;
merge have1(where=(year=2018) in=in1) have2(where=(year=2018) in=in2);
by indiv_id_num;
if in1 and in2;
run;
Assumes have1 and have2 are properly sorted by indiv_id_num.
This worked, but the final data set only contains observations that met those conditional statements. Is there a way to retain all observations regardless of whether they merge given the specified conditions?
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 save with the early bird rate—just $795!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.