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?

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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