BookmarkSubscribeRSS Feed
SAS_inquisitive
Lapis Lazuli | Level 10

Hello,

 

In this program,  the final table is not getting any records from table z  as there is matching column in table y and z (id2)?  I know intermediate table from first left join is not picking id2 = 12 record.  How do include second record from table y so it can be joined with table z?

 

data x;
	input id1 var1 $;
	cards;
1  a
2  b
;
run;

data y;
	input id1 id2 var2 $;
	cards;
1 11 c
3 12 d
;
run;

data z;
	input id2 var3 $;
	cards;
12 e
;
run;

proc sql noprint;
	create table want as
		select	a.var1,
			b.var2,
			c.var3
		from x as a
			left join y as b 
				on a.id1 = b.id1  
			left join z as c 
				on b.id2 = c.id2;
quit; 

 

1 REPLY 1
kiranv_
Rhodochrosite | Level 12

you need to do a full join in the begining , something like this

 

proc sql noprint;

create table want as

select a.var1,

b.var2,

c.var3

from x as a

full join y as b

on a.id1 = b.id1

inner join z as c

on b.id2 = c.id2;

quit;

 

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
  • 1 reply
  • 3389 views
  • 0 likes
  • 2 in conversation