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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: