BookmarkSubscribeRSS Feed
GN0001
Barite | Level 11

Hello all,

Can we say that match merge is like inner join in sql?

Please advise me.

Regards,

blue blue

Blue Blue
10 REPLIES 10
PaigeMiller
Diamond | Level 26

Yes, it is "like" inner join.

 

No, it is not identical to inner join.

--
Paige Miller
GN0001
Barite | Level 11

Hello Paige Miller,

 

You would say: "Yes, it is "like" inner join."

Doesn't it pull when the matches exist on left and right table?

then

You would say: "No, it is not identical to inner join."

 

Can you please elaborate it?

 

Regards,

 

Blue blue

Blue Blue
Reeza
Super User
Test what happens if you have duplicates in each tables.

PaigeMiller
Diamond | Level 26

@GN0001 wrote:

Hello Paige Miller,

 

You would say: "Yes, it is "like" inner join."

Doesn't it pull when the matches exist on left and right table?

then

You would say: "No, it is not identical to inner join."


I think you need to ask more specific and detailed questions. In my mind, on some criteria, merge is indeed "like" an inner join. On other criteria, merge is not "like" an inner join.

 

People have given examples of differences. There are probably other differences as well.

--
Paige Miller
ballardw
Super User

Here's a way to test this:

Make two data sets with the same named variables with the first variable all having the same value. Then do a match merge and an inner join on the two. Look at the results.

Similar- maybe under specific conditions. Depend on how loose your criteria is for setting likeness.

 

Data set1;
   input x y;
datalines;
1 1
1 2
1 3
1 4
;

data set2;
   input x y;
datalines;
1  11
1  22
1  33
;
GN0001
Barite | Level 11

Hello,

This is what I have, I can't understand what happens and how to control it. 

Thanks,

blue blue

Data set1;
Input x y;
dataline;
1 1
1 2
1 3
1 4
;


Data set2;
Input x z;
dataline;
1 11
1 22
1 33
;


data combined;
Merge set2 set1;
Run;
Blue Blue
Kurt_Bremser
Super User

@GN0001 wrote:

Hello,

This is what I have, I can't understand what happens and how to control it. 

Thanks,

blue blue

Data set1;
Input x y;
dataline;
1 1
1 2
1 3
1 4
;


Data set2;
Input x z;
dataline;
1 11
1 22
1 33
;


data combined;
Merge set2 set1;
Run;

You have neither a BY statement nor a Subsetting IF, so this ain't a match merge, you just put both datasets side-by-side.

Since you also have repeats of the common variable x in both datasets, you can't replicate the behavior of SQL (you have a many-to-many join).

GN0001
Barite | Level 11
Hello team,
I think I understood this part.
Regards,
blue blue
Blue Blue
Ksharp
Super User
1:1 or 1:n match is the same with both,
But n:n match is different .

of course, you need some following code to do like INNER JOIN .
data want;
merge a(in=ina) b(in=inb);
by id;
if ina and inb;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 10 replies
  • 1853 views
  • 10 likes
  • 6 in conversation