BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have a table named "salary" in a library named "lib1" and another table named "salary" in a library named "lib2". "Salary" in "lib1" contains the columns "id" and "payrate". "Salary" in "lib2" also contains the columns "id" and "payrate". The values in the columns of the "salary" table in "lib1" are not identical to the values in the columns of the "salary" table in "lib2".

In the 'select' clause of the code below, it is not specified which "salary" table is being referred to in "salary.id" and "salary.payrate". Also, in the 'where' clause, it is not specified which "salary" tables are being referred to in "salary.id=salary.id".

proc sql;
select salary.id, salary.payrate
from lib1.salary, lib2.salary
where salary.id=salary.id;
quit;

Does anyone know how I can specify that the "salary.id" in the select clause comes from "salary" in the "lib1" library and "salary.payrate" comes from "salary" in the "lib2" library? Also, how do I specify that the first "salary.id" in the 'where' clause specifies "salary.id" in "lib1" and the second "salary.id" specifies "salary.id" in "lib2"?

I tried the following code, but it didn't work and I got error messages:

proc sql;
select lib1.salary.id, lib2.salary.payrate
from lib1.salary, lib2.salary
where lib1.salary.id=lib2.salary.id;
quit;

I could rename the tables so they have different names, but I am curious to know if it is possible for the sql to work with the tables having the same name.

Thanks.
2 REPLIES 2
Cynthia_sas
Diamond | Level 26
Hi:
This may be the place where the use of AS in the FROM clause might help you out:
[pre]
libname perm 'c:\temp';
data perm.class;
set sashelp.class;
if age ge 14;
run;

proc sql;
select a.name, b.age, b.height
from perm.class as a, sashelp.class as b
where a.name=b.name;
quit;

[/pre]

cynthia

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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