Thank you to everyone who has responded. I have used bits of most of the replies and the code below now works for what I am needing. %let path='FILEPATH'; filename folder "&path"; data FilesInFolder; length Line 8 File $300; List = dopen('folder'); do Line = 1 to dnum(List); File = trim(dread(List,Line)); output; end; drop list line; run; data _NULL_; set FilesInFolder end=final; call symput(cats('File', _N_), trim(File)); call symput(cats('Name', _N_), trim(nliteral(substr(File,1,min(32, length(File)-4))))); if final then call symputx(trim('Total'), _N_); run; %macro loop_test; %do i = 1 %to &Total; %put &&File&i; %put %sysfunc(find(&&File&i,xls)); %if %sysfunc(find(&&File&i,xls)) %then %do; PROC IMPORT OUT=orig_test&i. DATAFILE="FILEPATH" DBMS=EXCEL REPLACE; GETNAMES=YES; SHEET="Sheet"; RUN; %end; %end; %mend; %loop_test;
... View more