BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
raivester
Quartz | Level 8

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?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller
raivester
Quartz | Level 8

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?

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 668 views
  • 0 likes
  • 2 in conversation