BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
krueg314
Calcite | Level 5

I was able to succesfully count the number of files in the New Folder in unix shell and output it to My SAS files folder

 

cd H:\My_SAS_Files\New_Folder

count='ls | wc -w'

{ echo -n 'Number of Files is ' & eval "$count"; } >> H:\My_SAS_Files\output

 

To Check Number of Files:

cd ..

tail output

 

I need to execute this in SAS to encoperate a loop and some macros, but I'm not sure how to get the X comamnd to work. Any ideas?

 

X "cd H:\My_SAS_Files\New_Folder";
X "count='ls | wc -w'";
X "{ echo -n 'Number of Files is ' & eval "$count"; } >> H:\My_SAS_Files\output";

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Unix is not going to be able to find any files on a directory name that starts with H:.

 

I find is is easier to code using a DATA _NULL_ and the PIPE engine.

 

%let path=/mydirectory ;

data file_count;
  infile "cd &path ; ls -A | wc -l" pipe;
  path="&path";
  input files;
run;

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

Unix is not going to be able to find any files on a directory name that starts with H:.

 

I find is is easier to code using a DATA _NULL_ and the PIPE engine.

 

%let path=/mydirectory ;

data file_count;
  infile "cd &path ; ls -A | wc -l" pipe;
  path="&path";
  input files;
run;
Ksharp
Super User
Make a Shell file  xx.sh and put all the command into it ,execute it at SAS side:

X '/home/xx.sh' ;

LinusH
Tourmaline | Level 20

Another option would be to use SAS external file functions.

May require some more programming lines the the shell counterpart, but you'll keep all logic in SAS.

 

Yet another option is to first call your shell script, then call SAS with your SAS program, avoiding the OS call from within SAS.

Data never sleeps

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 5219 views
  • 3 likes
  • 4 in conversation