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,

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 11820 views
  • 2 likes
  • 2 in conversation