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.
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;
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;
... or if you need two conditions:
.... ON x.Type = y.Type AND x.Year = y.Year
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;
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!
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.
Ready to level-up your skills? Choose your own adventure.