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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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