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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.