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!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.