Getting Started with SAS in UNIX Environments |
Introduction to Running SAS in Batch Mode |
To run SAS in batch mode, you specify your SAS program name in the SAS invocation command. You can run batch mode in the foreground, in the background by specifying an ampersand at the end of the SAS command, or submit your application to the batch queue by using the batch , at , nohup , or cron UNIX commands. (For more information, refer to the UNIX man pages for the batch , at , nohup , or cron commands.) If you start your application with one of these UNIX commands and you log off of your system, then your application will complete execution. If your application contains statements that start an interactive procedure such as FSEDIT, then you need to run your batch application in the foreground.
Invoking SAS in Batch Mode |
To invoke SAS in batch mode, you must specify a filename in the SAS command. For example, if weekly.sas is the file that contains the SAS statements to be executed, and you want to specify the NODATE and LINESIZE system options, you would enter the following command:
sas weekly.sas -nodate -linesize 90
The command would run the program in the foreground. If you want to run the program in the background, add the ampersand to the end of the command:
sas weekly.sas -nodate -linesize 90 &
SAS creates a .log file and a .lst file in the current directory that contains the log and procedure output.
Submitting a Program to the Batch Queue |
To submit your program to the batch queue, you can use the batch , at , nohup , or cron commands. For example, you could submit weekly.sas from your shell prompt as follows:
$ at 2am sas weekly.sas <control-D> warning: commands will be executed using /usr/bin/sh job 8400.a at Wed Jun 11 02:00:00 2008 $
If you create a file that contains the SAS command (for example, cmdfile.sh ) that is necessary to run your program, then you can enter the following command at your shell prompt:
at 2am < cmdfile.sh
SAS sends the output to a file that has the same name as the program. The output file has an extension of .lst. The log file writes to a file with an extension of .log. Both of these files are written to your current directory. Refer to the UNIX man pages for these commands for more information on submitting jobs to the batch queue. For more information about routing output, see Printing and Routing Output.
If you submit a file in batch mode, then a line that is greater than 256 bytes will be truncated. An explicit message about this truncation is written to the SAS log.
Note: If your program contains statements that start an interactive procedure such as the FSEDIT procedure, you will need to run your program as a foreground process.
Writing Data from an External File Using UNIX Pipes |
You can use a UNIX pipe to write data from an external file to a SAS program. For example, suppose that your data resides in the external file mydata and your SAS program myprog.sas includes this statement:
infile stdin;
Issue this command to have myprog.sas read data from the external file mydata :
cat mydata | sas myprog.sas
For information about using external files, see Using External Files and Devices. See File Descriptors in the Bourne and Korn Shells for another way to have a SAS program read data from an external file.
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.