BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I am trying to merge three datasets with inequal no of observations. Dataset A has 10 observations, Dataset B has 15 observations and dataset C has 3 observations. The objective of merging is to have a final dataset with a variable present in dataset C and it should have all the variables present in A.

Note: There are no common variables in dataset A and C.

I first sort dataset A and B with the common variable and merge them using the same common variable. The resultant dataset D is sorted by the same variable as in dataset C and are merged using the common variable.

After the merge the final dataset has blank obs in it and also when I am trying to sort the final data set using the same variable. It is giving me an error saying that there is an error in the sorting variable.

Please can you let me know what is wrong here?

Thanks,
APS
1 REPLY 1
1162
Calcite | Level 5
Have you tried this:

data X;
merge D (in=a) C (in=b);
by common_var;
if b;
run;

The "if b" should return only records where C has a record.


I've also found good success with PROC SQL and the LEFT JOIN / RIGHT JOIN / FULL JOIN functionality. I seem to recall that the way a DATA step and SQL merge is different, so sometimes one might be better suited to your application.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 1 reply
  • 857 views
  • 0 likes
  • 2 in conversation