BookmarkSubscribeRSS Feed
rakeshvvv
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….…….

9 REPLIES 9
jakarman
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 --<-----
rakeshvvv
Quartz | Level 8

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

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

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

jakarman
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

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

  command=catx('sas',program);

  infile execute pipe filevar=command end=eof ;

  do while (not eof);

     input;

     put _infile_;

  end;

run;

Ksharp
Super User

data _null_;

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

  input program $256.;

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

run;

Reeza
Super User

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

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

PegasusTT77
Fluorite | Level 6
Thank you 🙂

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
  • 9 replies
  • 5413 views
  • 10 likes
  • 8 in conversation