I'm a base SAS user but getting into SAS Viya. One thing I do frequently in base SAS is inventory files on the local network or my C drive as shown below:
filename pipedir pipe %sysfunc(quote( dir "C:\TEMP" /S )) lrecl=1000;
data indata;
infile pipedir truncover;
input line $char1000.;
run;
It returns raw information about the folder path, the contents of the folder, the subfolder paths and subfolder contents. Each file includes date/time modified, and file size in addition to the filenames. I can parse and combine the raw data to get exactly what I need which I then use to find new files and import them automatically.
However, when I run similar code in SAS Viya using an NFS mounted drive I only get the filenames for the immediate folder. No subfolders and none of the other information. This is useful enough for most purposes but not including the subfolders is going to be a problem. Does anyone know how to get the kind of information I get using my PC SAS version when using SAS Viya for a mounted drive? Because SAS Viya exists on a Linux server are there some Linux commands that can be run from my SAS code that give me what I need?
Wow! I was not sure where to put your changes in my line but it worked on the first try! Very nice. The format is different than in windows but the information is the same and it includes the subfolders. Much appreciated!
filename pipedir pipe %sysfunc(quote( dir ls -lR "C:\TEMP" )) lrecl=1000;
data DIR;
infile pipedir truncover;
input line $char1000.;
run;
Thanks! Yes. I was masking my path and pasted my example in the wrong format. I appreciate you making that clear and for letting me know I don't need DIR or quotes in the command statement. I pasted some code below that worked as you described.
filename pipedir pipe %sysfunc(quote(ls -lR /TEMP )) lrecl=1000; data DIR; infile pipedir truncover; input line $char1000.; run;
I'm very close but I'm getting some strange results:
filename pipedir pipe %sysfunc(quote(ls -lR "&pathDir" )) lrecl=1000;
data DIR;
infile pipedir truncover;
input line $char1000.;
run;
this code returns some values with the year and others with the time.
-rw-------. 1 ryanb domain users 40016 Aug 7 2023 FILENAME1.mor
|
-rw-------. 1 ryanb domain users 40016 Aug 14 10:10 FILENAME2.mor
|
It will provide one or the other but never both, at least in the sample I reviewed.
I looked up ls parameters and came across --full-time. It generates output a little different than before but everything is now consistent.
filename pipedir pipe %sysfunc(quote(ls -lR --full-time "&pathDir" )) lrecl=1000;
data DIR;
infile pipedir truncover;
input line $char1000.;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.