BookmarkSubscribeRSS Feed
jerry898969
Pyrite | Level 9

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

6 REPLIES 6
ballardw
Super User

The appropriate LS command should replace "dir /b/s c:\temp\*.shp"; Obviously use a Unix/Linux path in lieu of C:\temp

jerry898969
Pyrite | Level 9

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

ballardw
Super User

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.

Tom
Super User Tom
Super User

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=' ';

jerry898969
Pyrite | Level 9

Thank you both for your help.  I appreciate it.

Tom, thank you for pointing that out. 

Kurt_Bremser
Super User

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)

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 6775 views
  • 7 likes
  • 4 in conversation