Hi,
I want to left join all data from data2 onto data1.
Current:
data 1 (4 obs)
var1 | var2 |
aa | 11 |
bb | 22 |
cc | 33 |
cc | 55 |
data 2 (1 obs)
var10 | var11 | var12 |
xxx | yyy | zzz |
want:
var1 | var2 | var10 | var11 | var12 |
aa | 11 | xxx | yyy | zzz |
bb | 22 | xxx | yyy | zzz |
cc | 33 | xxx | yyy | zzz |
cc | 55 | xxx | yyy | zzz |
This is a "simple" cartesian join, do
proc sql;
create table want as select * from data1, data2;
quit;
Only one record from DATA2? Then
data want;
set data1;
if _n_=1 then set data2;
run;
But you are probably looking for:
proc sql;
create table want as select *
from data1 as a left join data2 as b
on a.var1=a.var1;
quit;
In fact, you don't even need to know the variable name VAR1:
proc sql;
create table want as select *
from data1 as a left join data2 as b
on 1=1;
quit;
which the SQL compiler will note is a cartesian product join.
This is a "simple" cartesian join, do
proc sql;
create table want as select * from data1, data2;
quit;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.