dear community,
I am trying to join 3 tables using proc sql and i have to use a variable (field) that I created with case when condition (as variable1). I need to merge this new variable1 to the 3rd table and sas is throughing off an error that it can't locate the variable1 (as it is created and not there on the 3 datasets). How can I join using the newly created variable?
eg;
proc sql;
create table new as
select a.*, case when (a.statuses=' ') and (a.reasons='') then a.check
when a.statuses =' ' then a.check_bp
else a.statuses end as current_status,b.height,c.weight
from one as a left join two as b
on (a.id=b.id)
left join three as c
on (current_status=c.status); quit;
ERROR: The following columns were not found in the contributing tables: current_status.
thanks in advance
thank you LinusH for replying. It didn't work with calculated. I had to create a view with another select statement and pick it from there to join the tables.
proc sql;
create view v_new as
select case when (a.statuses=' ') and (a.reasons='') then a.check
when a.statuses =' ' then a.check_bp
else a.statuses end as current_status,id
from one a;
create table new as
select a.*, v.current_status,b.height,c.weight
from one as a left join two as b
on (a.id=b.id)
left join v_new as v
on (b.id=v.id)
left join three as c
on (v.current_status=c.status); quit;
thanks,
thank you LinusH for replying. It didn't work with calculated. I had to create a view with another select statement and pick it from there to join the tables.
proc sql;
create view v_new as
select case when (a.statuses=' ') and (a.reasons='') then a.check
when a.statuses =' ' then a.check_bp
else a.statuses end as current_status,id
from one a;
create table new as
select a.*, v.current_status,b.height,c.weight
from one as a left join two as b
on (a.id=b.id)
left join v_new as v
on (b.id=v.id)
left join three as c
on (v.current_status=c.status); quit;
thanks,
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.