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

Hello SAS Experts,

 

I am trying to get all records from dataset have which are not in dataset have1:

 

data have;
a='A';output;
a='B';output;
a='C';output;
run;

data have1;
b='E';output;
run;

proc sql;
    create table want as
    select * from have
    where a not in (select a from have1);
quit;

 

I am wondering why there is no error message with "ERROR: Column a could not be found in the table/view identified with the correlation name have1."

 

If i change my code like this,i get the error message:

 

proc sql;
    create table want as
    select * from have x
    where a not in (select y.a from have1 y);
quit;

 

 

 

Thank you for helping,

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Without the alias SAS searches for a variable a in ANY table. 

Not the behaviour you'd expect unfortunately. 

View solution in original post

6 REPLIES 6
LinusH
Tourmaline | Level 20
In your sample the only column in have1 is b, not a.
Data never sleeps
aurel_hogea
Calcite | Level 5

Yes, that's right. Precisely for this i'm wondering why no error message. 

gamotte
Rhodochrosite | Level 12

Hi,

 

I don't have the answer but it seems that "a" has a special meaning in a subquery context. Indeed, if you replace

a with, for instance, ab in your request, the error shows up as expected.

 

proc sql;
    create table want as
    select * from have
    where a in (select ab from have1)
;
quit;

ERROR: The following columns were not found in the contributing tables: ab.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.

Other tests ;

Direct query

select a from have1 => Error message 

 Use of an existing table

    create table want as
    select * from have
    where a in (select a from sashelp.cars)
 => No error message

 

Reeza
Super User

Without the alias SAS searches for a variable a in ANY table. 

Not the behaviour you'd expect unfortunately. 

aurel_hogea
Calcite | Level 5

Thank you very much for your answers.

 

Regards,

gamotte
Rhodochrosite | Level 12

Do you have any idea of why it is so ?

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

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
  • 6 replies
  • 2167 views
  • 0 likes
  • 4 in conversation