SAS Programming - Using SAS® for Windows in Batch Mode (Oct 2022)
Benefits of Using SAS® for Windows Batch Mode:
- Scheduling the date/time for SAS programs to be executed
- Submitting large, computationally intensive SAS programs
- Submitting SAS programs with significant amounts of output written to the log and output
Ways to Run SAS in Batch Mode
There are two (2) Ways to Submit a Batch Job and Manage Output:
- Immediate SAS Job Execution
- Schedule a Date/Time for SAS Job Execution
Important Points When Running SAS® in Batch Mode
Batch programs run SAS® in the background in the Windows environment. When running in Batch Mode, the SAS windows such as the Editor, Log and Output windows are not displayed on the screen. Results are written directly to log (.log) and output (.lst) files for later viewing. Performance may improve to execute a SAS program since write the output to the screen for display is avoided.
The program may start executing immediately or placed in a queue behind other Windows jobs. Batch mode facilitates scheduling Batch jobs as needed. Off peak hours processing may help in better performance and run time.
Two Ways to Submit a SAS Batch Job and Manage Output
1/. Executing the Job Immediately In Windows Explorer. This SAS program file should have a .sas extension.
- Right-click on the SAS program you want to submit.
Note: The program Output (.lst) and Log (.log)files will be located in the same folder as the sas program. Consult SAS command options like -ALTLOG or -OUT to send the logs and .LST to desired location. For more details an oldie but good info is https://v8doc.sas.com/sashtml/win/zcoutput.htm
2/. Scheduling a SAS Batch Job to Run at a Specific Time
This method uses the Windows Task Scheduler to schedule a time and date for the batch job to be executed.
For Windows 7 / Windows 10 / windows 11:
A batch file is a file which can be used to execute jobs in Windows. It can be used to run one or multiple SAS jobs. There are Three (3) requirements:
- The path of your SAS software (sas.exe) on your computer
- The path to the location of the SAS program you wish to execute.
- (Optional) A line for each SAS program to execute using Windows Scheduler.
Step 1. Create a batch file (which has a .bat extension)
Go to the Windows Start Menu -/> All Programs -/> Accessories-/> Notepad
Each SAS job on one line:
- The path of the SAS software (with quotes around the path)
- -SYSIN
- The path of the SAS program which you want to execute using Windows Scheduler.
- Save the batch file as .BAT type file.
The batch file content to run a SAS program called MysasProg1.sas using SAS 9.4 will look like this:
"C:/Program Files/SASHome/SASFoundation/9.4" -SYSIN "C:/myjobs/MysasProg1.sas"The path of SAS software can be different for different installations.
Note: The path above is the default location for SAS 9.4 installs.
To submit multiple SAS programs in batch mode, the batch file will have one row like above for each of SAS programs (changing the path to the location of each program).
For example, the batch file content to run two SAS programs called MysasProg1.sas and SMysasrog2.sas using SAS 9.4 will look like this:
"C:/Program Files/SASHome/SASFoundation/9.4" -SYSIN "C:/myprogs/MysasProg1.sas"
"C:/Program Files/SASHome/SASFoundation/9.4" -SYSIN "C:/myprogs/MysasProg2.sas"Step 2: Navigate to Windows Start Menu -/> (in Search) Type Task Scheduler
You may get prompted for your password before scheduling
This schedules your job.
Note: If you are scheduling a job that will run on a SAS server and NOT your local personal machine, you may need to work with your IT administrator to allow access to local Server task Scheduler the remaining steps will remain as shown.