BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

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;
3 REPLIES 3
Tom
Super User Tom
Super User

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;
Ksharp
Super User

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;
AllanBowe
Barite | Level 11

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;
/Allan
MacroCore library for app developers
Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1221 views
  • 2 likes
  • 4 in conversation