Hello,
I'm trying to get the directory listing of shape files on Linux. When I do it on windows this code works, but I can't find the equivalent for Linux.
Filename filelist pipe "dir /b /s c:\temp\*.shp";
data shapefiles ;
infile filelist truncover ;
input filename $100. ;
run ;
I know linux uses ls for listing, but I'm not sure how to use it within the filename statement or do I have to use a different approach?
I'm using SAS 9.3 (TS1M2) on linux
Thank you
The appropriate LS command should replace "dir /b/s c:\temp\*.shp"; Obviously use a Unix/Linux path in lieu of C:\temp
Hi ballardw,
Thank you for your help. I was able to figure it out taking this approach.
rsubmit ;
data temp (keep=fname) ;
rc=filename("filelist", "~/shape/") ;
did=dopen('filelist') ;
nf=dnum(did) ;
do i=1 to nf;
fname=dread(did, i);
ext=scan(fname,-1) ;
if ext = 'shp' then output ;
end;
rc=dclose(did);
run ;
endrsubmit ;
Do you see any issues by taking this approach?
Thank you,
Jerry
There is absolutely nothing wrong with using the external file information functions. The PIPE options are really more useful when you have to run another program that directs output to standard output.
I would be a little more careful in determining the extension. Unix files could have no extension or even not have a dot at all. Or could have the dot as the first character.
if 1 < index(fname,'.') < length(fname) then ext=scan(fname,-1,'.');
else ext=' ';
Thank you both for your help. I appreciate it.
Tom, thank you for pointing that out.
The UNIX ls option for recursive listing of subdirectories is -R. You might also look at using the find command for your purpose, as it is much more powerful.
Keep in mind that using wildcards (? or *) in the command on UNIX may produce unexpected results, as the wildcards are expanded by the shell (unsing the contents of the current working directory) before handing off the commandline options to the command itself. Using the find command and -name \*.shp may be better. (the backslash prevents the shell from expanding the wildcards)
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.