DATA Step, Macro, Functions and more

MERGE

Reply
N/A
Posts: 0

MERGE

How would code a merge that will keep only observations that have match both the set.
N/A
Posts: 0

Re: MERGE

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;
Valued Guide
Posts: 2,175

Re: MERGE

Leena,
have you any rules for handling data which could match more than one row on either side?

PeterC
Super Contributor
Posts: 474

Re: MERGE

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
Valued Guide
Posts: 2,175

Re: MERGE

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
Super Contributor
Posts: 474

Re: MERGE

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
Ask a Question
Discussion stats
  • 5 replies
  • 159 views
  • 0 likes
  • 3 in conversation