DATA Step, Macro, Functions and more

Running several SAS Program Files at once

Reply
Contributor
Posts: 54

Running several SAS Program Files at once

I have several SAS programs in a folder that I run in sequence.  However I would like to create a batch program to run these SAS program files one-by-one instead of manually.

 

How would I code this?  

 

Thanks

Jack

PROC Star
Posts: 761

Re: Running several SAS Program Files at once

Contributor
Posts: 35

Re: Running several SAS Program Files at once

It sounds like you want to fully automate the process but keep the code separated, possibly for individual logs/troubleshooting/future changes? Regardless, I think what I would do is create a batch file and add it to the Windows task scheduler.

 

The batch file (.bat) would look something like this and would generate a date stamped log for each run,

Start/w "Auto Metrics" "C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -CONFIG "C:\Program Files\SASHome\SASFoundation\9.4\nls\en\sasv9.cfg" -sysin "Z:\blahblahblah\auto_metrics_code.sas" -log "Z:\blahblahblah\auto_metrics_log_%date:~-4,4%%date:~-7,2%%date:~-10,2%.txt" -print "Z:\blahblahblah\auto_metrics_log_%date:~-4,4%%date:~-7,2%%date:~-10,2%.lst"

Start/w "Auto Metrics" "C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -CONFIG "C:\Program Files\SASHome\SASFoundation\9.4\nls\en\sasv9.cfg" -sysin "Z:\blahblahblah\auto_metrics_code_STEP2.sas" -log "Z:\blahblahblah\auto_metrics_log_STEP2_%date:~-4,4%%date:~-7,2%%date:~-10,2%.txt" -print "Z:\blahblahblah\auto_metrics_log_STEP2_%date:~-4,4%%date:~-7,2%%date:~-10,2%.lst"

Start/w "Auto Metrics" "C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -CONFIG "C:\Program Files\SASHome\SASFoundation\9.4\nls\en\sasv9.cfg" -sysin "Z:\blahblahblah\auto_metrics_code_STEP3.sas" -log "Z:\blahblahblah\auto_metrics_log_STEP3_%date:~-4,4%%date:~-7,2%%date:~-10,2%.txt" -print "Z:\blahblahblah\auto_metrics_log_STEP3_%date:~-4,4%%date:~-7,2%%date:~-10,2%.lst"

Once you have the batch file working, just schedule it in the task scheduler at whatever cadence you see fit.

 

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

 

Contributor
Posts: 54

Re: Running several SAS Program Files at once

Great thanks.

Super User
Posts: 3,256

Re: Running several SAS Program Files at once

If you are running your programs on a SAS server you may want to consider using the batch and scheduling SAS jobs capabilities of SAS Management Console. It takes care of constructing correct SAS batch command lines without you having to construct them manually.

Super User
Posts: 7,824

Re: Running several SAS Program Files at once

On UNIX, I'd do

sas sas1.sas&
sas sas2.sas&
sas sas3.sas&
wait

The wait command will only finish once all the background jobs have finished.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 5 replies
  • 242 views
  • 2 likes
  • 5 in conversation