BookmarkSubscribeRSS Feed
gzr2mz39
Quartz | Level 8
I'm combining many files.
However, some of the files in my list do not exist.
If a file does not exist then I get an error and the new data set is not created.
How do I get around this problem?

data my;
set my_1-my_999;
run;
ERROR: File WORK.MY_3.DATA does not exist.
NOTE: The SAS System stopped processing this step because of errors.

Thank you.
2 REPLIES 2
monei011
Calcite | Level 5
The following is one solution to the problem that uses the dictionary tables and a macro variable to pass the list of existing datasets to the datastep that combines the datasets.

/*
simple example data to use to illustrate solution
*/

data a1;
x=1;
run;
data a2;
x=2;
run;
data a5;
x=5;
run;
data a6;
x=6;
run;
/*
use sas dictionary tables to find out the
names of the datasets that actually exist
in the library.
Then use the ability to generate a macro variable
containing a list of values separated by blanks
*/

proc sql;
create table tablenames as
select
memname
from dictionary.members
where libname="WORK"
;
select memname INTO :setlist SEPARATED BY ' '
from tablenames;
quit;
/*
see what the value of the macro variable is
*/
%put &setlist;
/*
use the macro variable which gets replaced by
the list of datasets
*/

data allx;
set &setlist;
run;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
The OP must be using SAS 9.2 because of the SET statement and using the hyphen for a consecutive file-range specification.

Additionally, some other options are using the OPTIONS setting NODSNFERR to convert the error to a warning message. And, with SAS 9.2, the file-prefix in the SET statement can be used with a trailing colon character.

Scott Barry
SBBWorks, Inc.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 2 replies
  • 1043 views
  • 0 likes
  • 3 in conversation