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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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