BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
jhsph07
Calcite | Level 5

Hi,

 

I have 2 data sets like below. 

 

Data one

A 1
A 2
B 1
B 2

 

Data two 
A Apple
A Peach
B Banana

 

I need to join them (Cartesian join), but only join by ID (A and B). 

 

This is what I want to get: 

 

A 1 Apple
A 1 Peach
A 2 Apple
A 2 Peach
B 1 Banana
B 2 Banana

 

If I use the below code, 

proc sql;
create table three as
select one.*
,two.*

from one
,two;
quit;

 

What I have got was 

A 1 Apple
A 1 Peach
A 1 Banana
A 2 Apple
A 2 Peach
A 2 Banana
B 1 Apple
B 1 Peach
B 1 Banana
B 2 Apple
B 2 Peach
B 2 Banana

 

Is there any way to only join by the ID (A, B)? 

 

Thank you very much!

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Amethyst | Level 16
proc sql;
create table three as
select one.*
,two.*
from one
,two
WHERE one.ID=two.ID
;
quit;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

2 REPLIES 2
yabwon
Amethyst | Level 16
proc sql;
create table three as
select one.*
,two.*
from one
,two
WHERE one.ID=two.ID
;
quit;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



jhsph07
Calcite | Level 5

Thanks a lot, it works!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2783 views
  • 0 likes
  • 2 in conversation