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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.