BookmarkSubscribeRSS Feed
alepage
Barite | Level 11

Hello,

 

I would like to get the list of all SPDE files, sas7bdat, xlsx and .dat  in a directory and its subdirectories on a Unix Server

For the spde file, I just want a name per file not each slice.

7 REPLIES 7
SASKiwi
PROC Star

Do you have the ability to run OS commands from your server SAS sessions? You can check this by running this program to see your XCMD setting:

proc options option = xcmd;
run;

If XCMD is on then you can run OS commands like - ls - to get a list of all files in a directory.

 

alepage
Barite | Level 11
Yes!

proc options option = xcmd;
30 run;

SAS (r) Proprietary Software Release 9.4 TS1M8

XCMD Enables the X command in SAS.
alepage
Barite | Level 11

Could you please provide an example of code using the x  command and sending the info in a dataset

Kurt_Bremser
Super User

@alepage wrote:

Could you please provide an example of code using the x  command and sending the info in a dataset


No X statement, but FILENAME PIPE:

data files;
infile pipe "find /path -name \*.sas7bdat";
input;
file = _infile_;
run;

But you should look at my presentation https://communities.sas.com/t5/SAS-User-Groups-Library/WUSS-Presentation-Talking-to-Your-Host/ta-p/8... which contains examples both for this and how to do it with SAS functions only.

alepage
Barite | Level 11
data files;
30 infile pipe "find /dwh_actuariat/sasdata/sas2023/be/auto -name \*.sas7bdat";

_______________________________________________________________
23
ERROR 23-2: Invalid option name "find /dwh_actuariat/sasdata/sas2023/be/auto -name \*.sas7bdat".

31 input;
32 file = _infile_;
33 run;
Reeza
Super User

I like using this macro %dirtree.

 

https://github.com/sasutils/macros/blob/master/dirtree.sas

 

%macro dirtree
/*---------------------------------------------------------------------------
Build dataset of files in directory tree(s)
----------------------------------------------------------------------------*/
(directory    /* Pipe delimited directory list (default=.) */
,out=dirtree  /* Output dataset name */
,maxdepth=120 /* Maximum tree depth */
);

Not sure anything will do the SPDE request, you'll likely need to wrangle the output yourself for that one. 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2036 views
  • 4 likes
  • 4 in conversation