Firstly, I'd point out that "dir" appears to be a misspelt libref, not a folder. If you are looking for files in a folder, you can use:
%macro get_filenames(location);
filename _dir_ "%bquote(&location.)";
data filenames(keep=fname);
handle=dopen( '_dir_' );
if handle > 0 then do;
count=dnum(handle);
do i=1 to count;
fname=subpad(dread(handle,i),1,5);/* extract first five letters */
output filenames;
end;
end;
rc=dclose(handle);
run;
filename _dir_ clear;
%mend;
%get_filenames("c:\temp\");
If you are looking for datasets in a library, you can use:
proc sql;
create table datasets as
select substr(memname,1,5) as dataset
from dictionary.tables
where libname='LIB'; /* must be uppercase */
either approach will produce a dataset of 'files' which can be subsequently 'stepped through'..