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

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 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
buddha_d
Pyrite | Level 9

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,

 

View solution in original post

2 REPLIES 2
LinusH
Tourmaline | Level 20
Try to use the CALCULATED key word.
Data never sleeps
buddha_d
Pyrite | Level 9

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,

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 13502 views
  • 2 likes
  • 2 in conversation