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

How can I intercept when a file is not there? And then the processing union continues. Thanks.

 

proc sql;
create table union_test as
   select * from Test_A
     union all
   select * from Test_B
    union all
  select * from Test_C;

quit;

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @Hoibai,

 

If you must use PROC SQL, check the existence of the datasets by querying DICTIONARY.TABLES:

proc sql noprint feedback;
select memname into :dsnames separated by ' union all select * from '
  from dictionary.tables
  where libname='WORK' & memname in ('TEST_A', 'TEST_B', 'TEST_C'); /* names in upper case! */
%if &sqlobs %then %do;
  create table union_test as
  select * from &dsnames;
%end;
quit;

The %IF condition (allowed in open code) prevents an error in the case that none of the datasets exists.

View solution in original post

5 REPLIES 5
Ksharp
Super User

You could use SET statement to repalce UNION ALL of SQL.

 

options nodsnferr;
data Test_A Test_B;
 set sashelp.class;
run;


data union_test;
 set  Test_A Test_B Test_C;
run;
Hoibai
Obsidian | Level 7

How can I intercept the file if it is not there?

Ksharp
Super User
If you want to know which dataset is not exist, then check dictionary table as FreelanceReinh showed .
FreelanceReinh
Jade | Level 19

Hello @Hoibai,

 

If you must use PROC SQL, check the existence of the datasets by querying DICTIONARY.TABLES:

proc sql noprint feedback;
select memname into :dsnames separated by ' union all select * from '
  from dictionary.tables
  where libname='WORK' & memname in ('TEST_A', 'TEST_B', 'TEST_C'); /* names in upper case! */
%if &sqlobs %then %do;
  create table union_test as
  select * from &dsnames;
%end;
quit;

The %IF condition (allowed in open code) prevents an error in the case that none of the datasets exists.

Tom
Super User Tom
Super User

You can use the NODSNFERR setting to suppress errors when datasets referenced do not exist. 

Will work if you just use normal SAS code to concatenate your datasets.

 

Example:

data test_a test_c;
  set sashelp.class;
run;

options nodsnferr;
data want ;
  set test_a test_b test_c;
run;
options dsnferr;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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