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?
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for 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.