03-27-2017 04:48 PM
I have an unknown number of files to read in from the F:\DATA directory. The following code is directly from SAS documentation... but I can't dicipher how to make it work for my directory where the file names are .dat extentions with an unknown/unlimited number batch files. Where do I put my infile statement, and where do I specify the file names (data01.dat, data02.dat, data03.dat....etc.)?
Thank you for any help!
LAN directory %macro drive(dir,ext);
%local filrf rc did memcnt name i;
/* Assigns a fileref to the directory and opens the directory */
/* Make sure directory can be open */
%if &did eq 0 %then %do;
%put Directory &dir cannot be open or does not exist;
/* Loops through entire directory */
%do i = 1 %to %sysfunc(dnum(&did));
/* Retrieve name of each file */
/* Checks to see if the extension matches the parameter value */
/* If condition is true print the full name to the log */
%if %qupcase(%qscan(&name,-1,.)) = %upcase(&ext) %then %do;
/* If directory name call macro again */
%else %if %qscan(&name,2,.) = %then %do;
/* Closes the directory and clear the fileref */
/* First parameter is the directory of where your files are stored. */
/* Second parameter is the extension you are looking for. */
03-27-2017 05:03 PM
The macro you pasted only creates a list of files.
Maybe this maybe more helpful?
If not, search on here, at least 3 solutions to this problem in last week.