Help using Base SAS procedures

Call all programs in a folder

Reply
Frequent Contributor
Posts: 145

Call all programs in a folder

I have folder and that has around 50-60 sas programs…. I would like to know if I can write a program to call all the programs in that folder….…….

Trusted Advisor
Posts: 3,215

Re: Call all programs in a folder

Posted in reply to rakeshvvv

You can do a directory listing and do an execute with an %include of all of them. Possible yes. Does it make sense? hardly.

What problem do you trying to solve? Is it about autocalling macros? 

---->-- ja karman --<-----
Frequent Contributor
Posts: 145

Re: Call all programs in a folder

I have around 60 programs which would creating listings for different scenarios.....Every week i have run them....so i have to call them individually....... I am just wondering if there is any option where we can save all those programs in a folder and write a program to call all those program located in that particular folder instead of running them individually........

Super User
Posts: 11,343

Re: Call all programs in a folder

Posted in reply to rakeshvvv

If you need them to run in a specific order then use of %Include is probably the way to go.

Create a SAS program that looks something like;

%include "c:\programfolder\prog1.sas";

%include "c:\programfolder\prog2.sas";

%include "c:\programfolder\prog3.sas";

If you have a long path it may be easier to have a macro variable hold it

%let folder = C:\folder\anotherfolder\program folder;

and then

%include "&folder.\prog1.sas";

Respected Advisor
Posts: 4,173

Re: Call all programs in a folder

Posted in reply to rakeshvvv

You could use a OS shell script as Tom suggests, or %include (but this executes everything as a single program), or MP connect.

Systask would be another option 6814 - Example of SYSTASK COMMAND statement to start a SAS batch job within aSAS program as it allows you to run programs independently, in sequence or in parallel (in combination with the "waitfor" statement) like you could do with a shell script - but you can code everything in SAS which is may be syntax you're more familiar with.

Trusted Advisor
Posts: 3,215

Re: Call all programs in a folder

Posted in reply to rakeshvvv

You are describing a scheduling facility, if you have no scheduler there are ways to simulate that.
The best thing is when they are all independent, no ordering just a start program.
Do not use the %include but run it as MP-Connect,  SAS-connecte licensed? or batch schript, (X-cmd open?

Reading the filenames in a directory is an easy part. Using Dopen dinfo will make it machine independent

http://support.sas.com/documentation/cdl/en/hostwin/67279/HTML/default/viewer.htm#p0qzctpnc6pi8sn1qc...

If you have a script every week running eg 03:00u am monday. (cron or whatever) you can read those names and start those. 
What to do with the logging? results? returncode?
 

---->-- ja karman --<-----
Super User
Super User
Posts: 7,076

Re: Call all programs in a folder

Posted in reply to rakeshvvv

You might be best to create an operating system command to do this.  For example in ksh on Unix you would just use this simple one line program.

for x in $(ls *.sas) ; do sas $x ; done

Of course if you want to check if the individual jobs completed correctly or other conditional processing decisions the task would get harder.  If you have a scheduling tool then perhaps you might want to use that.

You could write a SAS program.  If you don't care if the programs run in a separate session you can just %INCLUDE all of them.

%include "*.sas";

But that is a big IF because there can be serious side effects from running multiple independent programs in a single session.


If you have access to X commands then you can have SAS do what the FOR loop in KSH above was doing.


data _null_;

  infile "ls *.sas" pipe truncover ;

  input program $256.;

  command=catx('sas',program);

  infile execute pipe filevar=command end=eof ;

  do while (not eof);

     input;

     put _infile_;

  end;

run;

Super User
Posts: 10,044

Re: Call all programs in a folder

data _null_;

  infile "dir c:\temp\*.sas /s /b " pipe truncover ;

  input program $256.;

call execute(catx(' ','%inc',quote(program),';')) ;

run;

Super User
Posts: 19,869

Re: Call all programs in a folder

Posted in reply to rakeshvvv

Use %include with a wildcard, though the order may not be what you want:

%include 'path to folder\*.sas';

Ask a Question
Discussion stats
  • 8 replies
  • 1195 views
  • 9 likes
  • 7 in conversation