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

Hello SAS Users - Here is an example that is baffling me and my team mate. 

 

data test;
input name1 $ name2 $;
datalines;
AA BB
CC DD
EE FF
HH PP
;
run;

 

data name;
input code $;
datalines;
AA
FF
HH
;
run;

 

proc sql;
create table result as
select *  from test
where name1 in (select name1 from name) ;  /*name1 doesn't exist in the "name" dataset */
quit ;

 

NOTE: Table WORK.RESULT created, with 4 rows and 2 columns.

 

The last proc sql step should result in an error because there is no field called "name1" in dataset name but it does not give us an error.  Instead it does the search, and gives us the entire "test" dataset.  

 

But if I change the last proc sql to read like below: 

 

proc sql;
create table result as
select * from test
where name1 in (select x from name);
quit;

 

ERROR: The following columns were not found in the contributing tables: x.

 

Shouldn't I get an error response in both cases? Or maybe there is something I don't understand about SAS in this.  Thank you for any insight you can provide. 

1 ACCEPTED SOLUTION
5 REPLIES 5
FreelanceReinh
Jade | Level 19

Hello @MParthasarathy,

 

This was discussed in the 2021 thread Proc sql giving result when expected not to. Please see the solution there. Does it answer your question?

MParthasarathy
Fluorite | Level 6

Thank you all for your help. I will be trying these ideas to ensure I understand what is happening and try to learn new habits so I don't inadvertently end up with unexpected results and think they are ok - all because I didn't get an error. 

Tom
Super User Tom
Super User

But there is a variable NAME1, so SAS assumed that is the variable you wanted.  

324  proc sql feedback;
325  create table result as
326  select *  from test
327  where name1 in (select name1 from name) ;
NOTE: Statement transforms to:

        select TEST.name1, TEST.name2
          from WORK.TEST
         where TEST.name1 in
               ( select TEST.name1
                   from WORK.NAME
               );

NOTE: Table WORK.RESULT created, with 4 rows and 2 columns.

328  quit ;

If you meant some other variable named NAME1 then say so.

329  proc sql feedback;
330  create table result as
331  select *  from test
332  where test.name1 in (select name.name1 from name) ;
ERROR: Column name1 could not be found in the table/view identified with the correlation
       name NAME.
ERROR: Unresolved reference to table/correlation name name.
NOTE: Statement transforms to:

        select TEST.name1, TEST.name2
          from WORK.TEST
         where TEST.name1 in
               ( select name.name1
                   from WORK.NAME
               );

333  quit ;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 397 views
  • 4 likes
  • 5 in conversation