Dir is a unix command. You can instead use a pre-written macro to get the list of files that you will then need to likely filter to what you want to import. Chantge the first path in the %dirtree below to be your path and run the program. Note that I've set it to run/search only to a depth of 10 folders deep. If you want it go further change the maxdepth parameter. It will create a table called filelist that will have a list of the files/folders.
filename dirtree url
'https://raw.githubusercontent.com/sasutils/macros/master/dirtree.sas';
%include dirtree /source2;
%dirtree(C:\documents\data\ /* Pipe delimited directory list (default=.) */
, out=filelist /* Output dataset name */
, maxdepth=10 /* Maximum tree depth */);
This will contain the list of all files and folders. You can then use a data step to filter out the files that only have the xlsx extension.
data excel_file_list;
set filelist;
where type = 'F';
*test that this works,if it does uncomment the line below to filter only xlsx files;
ext = reverse(scan(reverse(filename), 1, "."));
*if ext = 'xlsx';
run;
@Emma2021 wrote: Sorry what is “Dir”? My path is as follow C://documents/data/… After this “data”, I have many sub folders with excel files
... View more