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,
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.