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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1103 views
  • 2 likes
  • 4 in conversation