I had been using the code below and do some parsing to create an inventory of the contents of a folder and subfolders including path, name of file, file extension, date modified, time modified, and file size. However, our IT department is taking away our ability to use the ls command inside Viya making this code obsolete.
filename pipedir pipe %sysfunc(quote(ls -lR --full-time "&pathDir" )) lrecl=1000;
data DIR_RAW;
infile pipedir truncover;
input line $char1000.;
run;
I was directed to other SAS options such as data information functions (Paper Template (lexjansen.com) but from what I can tell they're pretty limited. For example, I can get the filename but not the path if the file is in a sub-folder. I also can't seem to find a way to get the date modified, time modified, or file size.
If I only needed to inventory SAS datasets then I could use proc datasets (SAS Help Center: Requesting a Directory Listing for a SAS Library) to get most of the information I need, but I need all file types. It also doesn't seem to include sub-folders.
Any ideas? Using SAS Viya V.03.05M0P111119
The %dirtree() macro should provide the functionality you need.
The %dirtree() macro should provide the functionality you need.
I'd recommend using the BasePlus package, in particular the %dirsandfiles() macro. The macro gives you the list of files and sub-directories (with content) plus all that "metadata" stuff. It works OS independent, so on Win/Linux/UNIX.
This article, Appendix B, page 20, gives you quick instruction on how to install and use the package.
Bart
If you want to code this yourself instead of using a foreign macro, look at my presentation Talking to Your Host
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.