Using SAS® for Windows in Batch Mode
Using SAS® for Windows in Batch Mode is useful for :
- 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
About Running SAS in Batch Mode
Two Ways to Submit a Batch Job and Manage Output
About 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 viewing at a later time. This can speed up the amount of time it takes to execute a SAS program since it does not also need to write the output to the screen for display.
When a SAS program is submitted in batch mode, the program may start executing immediately, or it will be put in queue behind other Windows jobs. Batch jobs can also be set up to run at specific times, such as when the computer is not in use or may run in the background while the user continues to work on the computer.
Two Ways to Submit a SAS Batch Job and Manage Output
1. Executing the Job Immediately In Windows Explorer
- Right-click on the SAS program you want to submit.
- For SAS® 9.3: From the pop-up menu, select Batch Submit for SAS® 9.3.
- For SAS® 9.4: From the pop-up menu, choose Batch Submit for SAS® 9.4.
- This SAS program file should have a .sas extension.
- After execution, the program Output (.lst) and Log (.log)files will be located in the same folder as your .sas program.
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:
- A batch file is a file which can be used to execute jobs in Windows.
It can be used to run one or many SAS jobs.
It needs to include both:- The path of your SAS software (sas.exe) on your computer
- The path to the location of the SAS program you wish to execute.
It should contain a line for each SAS program you want 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
- Type on one line:
1. The path of the SAS software (with quotes around the path)
2. – SYSIN
3. 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 SASProg1.sas using SAS 9.3 will look like this:
"C:\Program Files\SASHome\SASFoundation\9.3" -SYSIN “C:\myprogs\SASProg1.sas”
-
The path of SAS software can be different for different installations.
The above path is the default location where SAS 9.3 installs.
Default path for SAS 9.2: "C:\Program Files\SAS9.2\SASFoundation\9.2\sas.exe" -
To submit multiple SAS programs in batch mode, the batch file will have one row like above for each of your SAS programs you wish to execute in batch mode (changing the path to the location of each program). For example, the batch file content to run two SAS programs called SASProg1.sas and SASProg2.sas using SAS 9.3 will look like this:
"C:\Program Files\SASHome\SASFoundation\9.3" -SYSIN “C:\myprogs\SASProg1.sas”
"C:\Program Files\SASHome\SASFoundation\9.3" -SYSIN “C:\myprogs\SASProg2.sas”
-
Step 2:
- Go to the Windows Start Menu -> All Programs -> Accessories -> System Tools -> Task Scheduler
- Double-Click on Create Basic Task
- This brings up the Create BasicTask Wizard.
For Windows XP:
- Go to the Start Menu -> All Programs -> Accessories -> System Tools -> Scheduled Tasks.
- Double-click on Add Scheduled Task.
- This brings up the Scheduled Task Wizard.
- Next to the scrollable list of Applications, select the Browse button.
- For SAS® 9.3: Select SAS 9.3 (English) in the scrollable list.
- For SAS® 9.2: Select SAS 9.2 (English) in the scrollable list.
- Select One time only for when to perform this task.
- Specify the time and date you want the batch job to be executed.
- The next window may ask you to enter your Windows password.
**If Windows is password-protected, you need to enter your password in order for your batch job to be executed.** - At the final window, select Open advanced properties for this task when I click Finish.
- In the advanced properties window on the Task tab, modify the Run and Start Instatements:
- In the Run statement specify the location of your sas.exe file followed by a SYSIN option and the path of your SAS program.
For SAS 9.2 the statement should be modified to look like the following:
"C:\Program Files\SAS9.2\SASFoundation\9.2\sas.exe " -sysin "C:\MyBigProgram.sas"
For SAS 9.3 the statement should be modified to look like the following:
"C:\Program Files\SASHome\SASFoundation\9.3\sas.exe" -sysin "C:\MyBigProgram.sas"
Note: In the Browse window, choose "All Files" under File Type to see your SAS programs. - Modify the Start In statement to specify the folder to where you would like the output files to be written.
- In the Run statement specify the location of your sas.exe file followed by a SYSIN option and the path of your SAS program.
This article was updated: 04/27/2020