DATA Step, Macro, Functions and more

combining many files when some are missing

Reply
Regular Contributor
Posts: 199

combining many files when some are missing

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.
Occasional Contributor
Posts: 12

Re: combining many files when some are missing

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;
Super Contributor
Super Contributor
Posts: 3,174

Re: combining many files when some are missing

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.
Ask a Question
Discussion stats
  • 2 replies
  • 207 views
  • 0 likes
  • 3 in conversation