BookmarkSubscribeRSS Feed
deleted_user
Not applicable
How would code a merge that will keep only observations that have match both the set.
5 REPLIES 5
deleted_user
Not applicable
Try this
first sort the two data sets basis the matching variable then apply the code below;

data target_dataset;
merge src_dataset1 (in = a) src_dataset2 (in = b);
by ;
if a & b then output;
run;
Peter_C
Rhodochrosite | Level 12
Leena,
have you any rules for handling data which could match more than one row on either side?

PeterC
DanielSantos
Barite | Level 11
For a 1-to-N match stick with the data/merge.

For a N-to-N match, the easiest way would be coding it through SQL.

To my knowledge, data/merge N-way match is actually possible, but it involves using an index and a requires one of the tables to be quite small, on top of that the implementation is quite obscure.

If you are running 9.2 you could try the new features of the hash object, being one, the possibility to load into the hash object multiple obs with the same key.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt
Peter_C
Rhodochrosite | Level 12
Daniel
since the data-step merge is easier than SQL unless n-n join/merge is required, I had to ask my question
Regards
PeterC
DanielSantos
Barite | Level 11
Yes, Peter.

I was just discussing my point of view of the 1-N/N-N scenarios.

Your question makes perfect sense to me, I would go for the SQL only for a N-to-N match. I also found Merge easier than SQL, and a lot more "controlable".

Cheers from Portugal.

Daniel Santos @ www.cgd.pt

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 955 views
  • 0 likes
  • 3 in conversation