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

Hello,

How do you appropriately select Employee_Gender (a column that does NOT exist in Donor_list table)?  This syntax gives me an ERROR: Unresolved reference to table/correlation name b.  However, if I include the Employee_payroll table on original FROM statement I get ERROR: Ambiguous reference, column Employee_ID is in more that one table.  What am I missing?

proc sql;

     select a.Employee_ID, a.Employee_Name, b.Employee_Gender

     from Mydata.Donor_list as a

     where Employee_ID in

          (select b.Employee_ID

           from SQL.Employee_payroll as b

           where a.Employee_ID = b.Employee_ID)

quit;

Thanks,

David

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

In this case, how about using an inner join instead of a sub-query:

proc sql;

     select a.Employee_ID, a.Employee_Name, b.Employee_Gender

     from Mydata.Donor_list as a, SQL.Employee_payroll as b

        where a.Employee_ID = b.Employee_ID

quit;

View solution in original post

4 REPLIES 4
Haikuo
Onyx | Level 15

In this case, how about using an inner join instead of a sub-query:

proc sql;

     select a.Employee_ID, a.Employee_Name, b.Employee_Gender

     from Mydata.Donor_list as a, SQL.Employee_payroll as b

        where a.Employee_ID = b.Employee_ID

quit;

David_S
Fluorite | Level 6

Hi Hai,

Don't know why a join didn't cross my mind.  That worked.  Thank you,

David

art297
Opal | Level 21

You'll have to add a semi-colon, just before the quit statement, in order for Haikuo's code to run.

And, dependent upon one's preferences, the following code does the same thing:

proc sql;

   select a.Employee_ID, a.Employee_Name, b.Employee_Gender

      from Mydata.Donor_list as a

        inner join SQL.Employee_payroll as b

          on a.Employee_ID = b.Employee_ID

  ;

quit;

Haikuo
Onyx | Level 15

Thanks, Art. Obviously my compiler wasn't working :smileysilly:

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 2522 views
  • 3 likes
  • 3 in conversation