BookmarkSubscribeRSS Feed
Quartz | Level 8

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….…….

Barite | Level 11

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 --<-----
Quartz | Level 8

I have around 60 programs which would creating listings for different scenarios.....Every week i have run 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

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\";

%include "c:\programfolder\";

%include "c:\programfolder\";

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.\";

Opal | Level 21

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.

Barite | Level 11

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

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 Tom
Super User

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.;


  infile execute pipe filevar=command end=eof ;

  do while (not eof);


     put _infile_;



Super User

data _null_;

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

  input program $256.;

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


Super User

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

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

Fluorite | Level 6
Thank you 🙂



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 9 replies
  • 8 in conversation