Hello
What is the way to ask see all files exists in a path (I dont want to get also folder exists ).
This querty show files and folders and I want to get only files
data have;
rc=filename('xx',"/usr/local/SAS/SASUsers/LabRet/UserDir/RRR/");
did=dopen('xx');
do i=1 to dnum(did);
fname=dread(did,i);
output;
end;
rc=dclose(did);
run;
Just try to open the file with DOPEN() to tell if it is a directory or not.
%let path=~/;
data have;
rc=filename('xx',"&path.");
did=dopen('xx');
if did then do i=1 to dnum(did);
fname=dread(did,i);
rc2=filename('yy',cats("&path.",fname));
did2=dopen('yy');
if did2 then rc2=dclose(did2);
else output;
end;
rc=dclose(did);
run;
Tom has already given you answer.
data have;
rc=filename('xx',"c:\temp\");
did=dopen('xx');
do i=1 to dnum(did);
fname=dread(did,i);
flag=0;
rc=filename('temp',"c:\temp\"||strip(fname));
d=dopen('temp');
if d then do;flag=1;rc=dclose(d);end;
output;
end;
rc=dclose(did);
drop rc did i d;
run;
If you'd like to do this recursively, you can try this macro: https://core.sasjs.io/mp__dirlist_8sas.html
Usage:
%mp_dirlist(path=/some/location, outds=myTable, maxdepth=MAX)
data work.results;
set work.mytable;
where file_or_folder='file';
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.