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

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

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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