BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ryanb2
Quartz | Level 8

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?

1 ACCEPTED SOLUTION

Accepted Solutions
gwootton
SAS Super FREQ
In Windows, dir /S is a recursive path listing, the equivalent command in linux would probably be ls -lR /path/to/read.
--
Greg Wootton | Principal Systems Technical Support Engineer

View solution in original post

6 REPLIES 6
gwootton
SAS Super FREQ
In Windows, dir /S is a recursive path listing, the equivalent command in linux would probably be ls -lR /path/to/read.
--
Greg Wootton | Principal Systems Technical Support Engineer
Ryanb2
Quartz | Level 8

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;

gwootton
SAS Super FREQ
I'm pleased you got what you were looking for! To clarify, this line:

filename pipedir pipe %sysfunc(quote(dir "C:\TEMP" /S)) lrecl=1000;

Is creating a fileref called "pipedir" that when called runs the command 'dir C:\TEMP" /s' and provides the output of this command through the fileref.

Linux doesn't have drive letters, so it's temp directory is typically /tmp. Instead of running "dir" we are running "ls", so "dir" would not be needed any longer. So, a comparable line for Linux would be (I'm removing the sysfunc and quote pieces since I don't think they're needed here):

filename pipedir pipe "ls -lR /tmp" lrecl=1000;
--
Greg Wootton | Principal Systems Technical Support Engineer
Ryanb2
Quartz | Level 8

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;
Ryanb2
Quartz | Level 8

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. 

It will provide one or the other but never both, at least in the sample I reviewed.

 

Ryanb2
Quartz | Level 8

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Discussion stats
  • 6 replies
  • 583 views
  • 2 likes
  • 2 in conversation