BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Phil_NZ
Barite | Level 11

Hi SAS Users,

 

Today I tried to inner join two datasets "winsed.merge_treat_con" and "_9b_lag" based on two variables "Year" and "Type" (both are character variables)

In the joined dataset, I want to have all variables of the winsed.merge_treat_con and these variables del_exc_rat, lagcogs, lagsel_gen_adm, lagope_lea_exp, lagr_and_d, laggoodwill from _9b_lag.

 

My code based on one condition is as below

PROC SQL;
Create table innerjoin_ as
Select * from winsed.merge_treat_con as x, del_exc_rat lagcogs lagsel_gen_adm lagope_lea_exp 
		lagr_and_d laggoodwill from _9b_lag	as y
where x.Type = y.Type;
Quit;

I am not sure how can I deal with two conditions and apart from Proc SQL, and whether we can use other ways to merge inner join like that (because sometimes SQL consumes quite a bit of ram).

 

Many thanks and warm regards.

Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.
1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

There are many syntax errors in your sql code.

Compare it to next code:

PROC SQL;
	Create table innerjoin_ as
	Select x.*,
	       y.del_exc_rat,
		   y.lagcogs,
		   y.lagsel_gen_adm,
		   y.lagope_lea_exp, 
		   y.lagr_and_d,
		   y.laggoodwill
	from winsed.merge_treat_con as x
	inner join 	work._9blag	as y	
	on x.year=y.year and x.Type = y.Type;
Quit;

View solution in original post

3 REPLIES 3
utrocketeng
Quartz | Level 8

it sounds this might be what you are after

 

PROC SQL;
Create table innerjoin_ as
Select 
	x.*
	, del_exc_rat 
	, lagcogs 
	, lagsel_gen_adm 
	, lagope_lea_exp 
	, lagr_and_d 
	, laggoodwill
from 
	winsed.merge_treat_con as x
	INNER JOIN _9b_lag	as y ON x.Type = y.Type;
Quit;
PGStats
Opal | Level 21

... or if you need two conditions:

 

.... ON x.Type = y.Type AND x.Year = y.Year

PG
Shmuel
Garnet | Level 18

There are many syntax errors in your sql code.

Compare it to next code:

PROC SQL;
	Create table innerjoin_ as
	Select x.*,
	       y.del_exc_rat,
		   y.lagcogs,
		   y.lagsel_gen_adm,
		   y.lagope_lea_exp, 
		   y.lagr_and_d,
		   y.laggoodwill
	from winsed.merge_treat_con as x
	inner join 	work._9blag	as y	
	on x.year=y.year and x.Type = y.Type;
Quit;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 3 replies
  • 3762 views
  • 1 like
  • 4 in conversation