Running SAS in batch mode in Windows OS

This post will discuss executing SAS batch jobs under Windows operating systems. The screen shots for
Windows 2000, Windows 95/98/ME/XP may be slightly different.
(Note: For all the examples in this document, assume that the SAS System is installed in the
"C:\Program Files\SAS\SAS 9.1\" directory. Change the path as necessary).
Steps required for Execution:
 Preparing your SAS command (program) file
 Submitting the command file for processing
 Reviewing the outputs of the command file

Preparing your SAS command (program) file
Prepare your SAS program and save it as c:\Project\progs\testprog.sas …

For eg.
Here we are setting the linesize and the pagesize for the SAS Output program.
options linesize=80 pagesize=60;

data one;
input id name :$20. amount ;
date=today();
format amount dollar10.2
date mmddyy10.;
label id="Customer ID Number";
datalines;
1 Grant 57.23
2 Michael 45.68
3 Tammy 53.21
;
proc print data=one;
run;

Submitting the command file for processing
The general syntax of the Batch file processing command is
SASExecutableLocation -SYSIN “program name to execute.sas” –Print “The SAS output redirect
location.lst” –Log “The Log redirect location.log”
For our example
The Project directory looks like this….

Progs – All the programs are placed in this directory
Out- Output from the programs
Log- Log for the Programs

Prepare the command to Process i.e.
"C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin "C:\Project\progs\testprog.sas" -print
"C:\Project\out\testprog.lst" -log "C:\Project\log\testprog.log"
The –SYSIN option is used to change the destination folder for the SAS program.
The –PRINT option is used to change the destination folder for the output of the program.
The –LOG option is used to change the destination folder for the log of the program that has been

executed.
NOTE: If you do not specify the -print and –log options the SAS output and Log go to the same location
as the Programs ( C:\ in our example). In this case the command can be simply used as " C:\Program Files\SAS\SAS 9.1\Sas.exe" -SYSIN “c:Project\progs\testprog.sas”
To execute the SAS program, go to your computer
Start | Run and copy and paste this command and hit OK/Enter.

Or alternatively
go to your computer
Start | Run
type cmd in the text field hit OK. This will open the MS-DOS Prompt…

then type
"C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin "C:\Project\progs\testprog.sas" -print
"C:\Project\out\testprog.lst" -log "C:\Project\log\testprog.log"

Or alternatively
Save the command in a .bat file and then execute it by double clicking the file or executing from MSDOS prompt.
For eg. Command saved in a c:\Project\bat\prog.bat file

go to your computer Start | Run
then type cmd to open MS DOS Prompt…
then change directory to “c:\Project\bat\”
then type prog (i.e no need type the extension .bat)
Hit Enter

This should kick off SAS on the SAS program in Batch mode…

Reviewing the output of the command file
When there are no programming errors left in the command file, the submitted program will produce an
output, if any, at the output location mentioned i.e. C:\Project\out\testprog.lst and the Log is re-directed to
the Log location mentioned i.e. C:\Project\log\testprog.log.

If you find any errors in the Log file…then edit the SAS Program to correct the issue and re-submit with
the command.

Read more at @ http://sastechies.blogspot.com/