BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
HitmonTran
Pyrite | Level 9

Hi,

 

I want to left join all data from data2 onto data1.

 

Current:

data 1 (4 obs)

var1var2

aa

11
bb22
cc33
cc55

 

data 2 (1 obs)

var10var11var12
xxxyyyzzz

 

want:

var1var2var10var11var12

aa

11xxxyyyzzz
bb22xxxyyyzzz
cc33xxxyyyzzz
cc55xxxyyyzzz
1 ACCEPTED SOLUTION
2 REPLIES 2
mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 617 views
  • 2 likes
  • 3 in conversation