SAS is a comprehensive program used by SSCC researchers for data management and statistical analysis. It can be run in both a Windows-like or batch environment on Linux. SSCC has version 9 of SAS installed on Linux, Windows Terminal Server (Winstat1-3), and the lab PCs in Social Science 3218 and 4218. This article explains how to run SAS jobs on Linux. For an introduction to writing SAS programs to work with data, see An Introduction to SAS Data Sets.
SAS can be invoked simply by typing the word "sas" at the Linux prompt. To take advantage of the many options available with the command, use the general form of the SAS command as follows:
sas filename -option1...-optionn
where filename gives the name of the file containing the SAS program to be executed. Specifying a filename on the SAS command invokes SAS in batch mode.
options specifies a SAS system option to configure your session. Some options include:
-linesize n specifies the line size of the SAS output. The range of linesize is 64 to 256. The default is 132 for batch mode.
-obs n specifies the last observation from a data set that SAS is to read.
-pagesize n specifies the number of lines that can be placed in a page of SAS output. Values can range from 15 to 32,767. The default is 60.
-memsize n specifies the maximum amount of memory a procedure call may use. The default is 64mb.
-log file specifies that SAS write the log of the SAS session to "file". By default, the SAS log is written to the file filename.log where filename is the name of the file containing the SAS commands.
-print file specifies that SAS write the SAS output to "file". By default, the SAS output is written to the file filename.lst where filename is the name of the file containing the SAS commands.
sas test1 -obs 0 -noreplace
This command executes the program test1.sas, the file containing the SAS commands, with the system options OBS and NOREPLACE. These two options used together are a good way of checking to make sure your syntax is correct in your file containing the SAS statements. It causes SAS to execute each DATA and PROC step in the program without actually reading any of the data.
Modes of Execution
This section describes how to invoke SAS in the Interactive SAS Windowing Environment and batch modes.
Interactive SAS Windowing Environment Mode
SAS can only be accessed in this mode from an X-display such as a Windows-based Terminal or a PC running software like X-Win32.
Typing sas at the Linux prompt brings up SAS in the Windowing Environment mode. The SAS Windowing Environment is an interactive windowing system that enables you to write and modify your programs, run them, and monitor the output. You can use menus or type commands within the SAS Windowing Environment. Choose File: Exit from the menu to terminate the SAS Windowing Environment and return control to the operating system.
Note: If after typing sas on the command line, you see a 1? prompt on your screen, you are NOT in the SAS Windowing Environment but in old-style interactive line mode. Typing endsas; at the 1? prompt will take you back to the Linux prompt. The SAS Windowing Environment is only available from X-displays.
To invoke SAS in batch mode, enter the SAS command followed by the name of the file containing the SAS program to be executed. For example, suppose you have stored your SAS statements in a file named pums90.sas. To invoke SAS and execute the program you would type the following:
Note that you do not have to include the file extension in the filename when the file extension is .sas. SAS uses .sas by default.
You do not get another Linux prompt until SAS finishes executing the program. When SAS finishes and you get the Linux prompt, two new files are in your working directory which contain the SAS output. pums90.log contains the log of the SAS session and pums90.lst contains the output from the SAS commands in pums90.sas..
Note: If you have stored your SAS statements in a file which has some file extension other than .sas, the log and lst files that are created will have filenames that include the extension. For example, if your command file was named pums90.ext, the log file created would be pums90.ext.log and the output file would be pums90.ext.lst
In the example just shown, SAS created two files: one to hold the SAS output and the other one for a log of session messages. If you want to direct your output and log to other files, use the PRINT and LOG system options. For example,
sas pums90 -print report -log report.log
The output goes to file report and the log goes to file report.log.
Running SAS Jobs in the Background
To execute a program in the background, you simply type an & at the end of the command. For the pums90.sas example above, type the following:
sas pums90 &
Your job will then be executed in the background, meaning you do not have to wait until the SAS program finishes execution before you get the Linux prompt. In other words, your shell is available for other work. Submit only one SAS background job at a time on any one Linux server.
Online documentation for SAS 9 is available at http://support.sas.com/documentation/onlinedoc/sas9doc.html
We also have printed copies of the version 6 manuals and other SAS books on programming and statistical topics which you may find useful. These manuals are available for short term loan in the CDE Print Library, Social Science 4457.
SSCC staff have prepared many articles on using SAS. These are available in the SSCC Knowledge Base.
To subscribe to the SAS listserv, visit http://www.stattransfer.com/lists.html. This web site provides a subscription service to all the major statistical software listservs including SAS. The SAS listserv provides a depth of information and support that is essentially impossible for staff at any one institution (like ours) to duplicate.
Last Revised: 3/14/2007