The following macro might do the job;
%macro procesFilesInRoot(rootFolder,fileExt,procesMacro);
%put "dir ""%unquote(&rootFolder)"" /s /b";
filename pipeTree pipe "dir ""%unquote(&rootFolder)"" /s /b" lrecl=32767;
data fullNames;
infile pipeTree truncover;
input fullName $char1000.;
ext = upcase(scan(fullName,countw(fullName, '.'), '.'));
if ext = "%upcase(&fileExt)";
run;
filename pipeTree clear;
title 'files found';
proc print;
run;
proc sql noprint;
select count(*) into :nrFiles from fullNames;
%let nrFiles = &nrFiles; /** to strip the leading blanks **/
%if &nrFiles %then %do;
select fullName into :fullName1-:fullName&nrfiles from fullNames;
%end;
quit;
%do fileNr = 1 %to &nrFiles.;
%&procesMacro(&&fullName&fileNr);
%end;
%mend;
Before using it, you need to write a macro that processes a single input file;
%macro import1file(fullName);
%let fileName = %scan(&fullName,%sysfunc(countw(&fullName, '\')), '\');
%let fileExt = %scan(&fileName,%sysfunc(countw(&fullName, '.')), '.');
%let dataName = %substr(&fileName,1, %length(&fileName)-%length(&fileExt)-1);
proc import datafile = "&fullName" out=&dataName;
run;
%mend;
Then you can use it as follows;
%procesFilesInRoot(D:\Horsten,txt,import1file);