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!
proc sql;
create table three as
select one.*
,two.*
from one
,two
WHERE one.ID=two.ID
;
quit;
proc sql;
create table three as
select one.*
,two.*
from one
,two
WHERE one.ID=two.ID
;
quit;
Thanks a lot, it works!
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.
Ready to level-up your skills? Choose your own adventure.