Using SAS on Unix

SAS (Statistical Analysis System) provides facilities for the manipulation, analysis and graphical representation of both numeric and character data using a variety of techniques. This document describes the Unix implementation of SAS version 8.1. It assumes that you have a working knowledge of Unix.

Documentation

SAS is documented by many manuals, amounting to many thousands of pages. A locally-written introduction to the package - Practical introduction to SAS on Unix (document sas-t1) - is available on-line.

SAS divides the description of its main facilities into separate user guides covering 'Language', 'Procedures', 'Language and Procedures', 'SAS/STAT (statistics), 'ETS' (Econometric and Time Series Analysis) and 'SAS/GRAPH' (graphics), but these are arbitrary divisions and any facility may be used freely with any other.

SAS Language and Procedures: Usage provides an introduction to SAS language and procedures. This book is a tutorial for the base SAS software. It does not attempt to cover all features of the system, but instead focuses on certain tasks. It describes how to input data; sort data, merge two or more data sets; produce frequency tables; cross-tabulations; descriptive statistics such as mean, standard deviation, etc; lay out tables in various ways; produce charts and plots of various types, and how to inspect and edit your data after it has been input.

SAS Language: Reference provides detailed reference information on SAS language statements, functions, formats, informats, display manager, or any other part of the base system except procedures.

SAS Procedures Guide provides detailed information on SAS base software procedures.

SAS/STAT User's Guide: Volumes 1 and 2 describe the procedures available for regression, analysis of variance, categorical data analysis (for example probit), factor analysis, principal components analysis, canonical correlation analysis, discriminant analysis, cluster analysis, ranking data and manipulation of matrices.

SAS/ETS User's Guide describes the procedures available for Econometrics and Time Series analysis such as forecasting and autoregression.

SAS/GRAPH Software: Volumes 1 and 2 describes how to specify the graphics device to be used and how to draw charts, plots, maps, graphs etc.

There are also other more specialised manuals, describing details of particular applications.

Two further manuals are intended as a simple introduction to SAS and its relation to the operating system. These are the 'SAS Introductory Guide' and the 'SAS Companion for the Unix Environment and Derivatives'. The 'SAS Applications Guide' and 'SAS Guide to Macro Processing' describe some more advanced use of SAS.

SAS has an internal help system which can provide you with information at the terminal. For details, enter SAS and type the command:

HELP HELP;

Back to top

Running SAS on Unix

The statements to run SAS facilities may be typed interactively or put into a file. Each SAS statement is separated from the next by a semicolon (;). A statement may spread over several lines or several statements may appear on one line.

Output can be directed to the terminal or to a file which can be printed later if required. Data can be included with the statements or can be read from files.

It is recommended that the statements be input to a file as this avoids retyping them each time. If you type your SAS statements at the terminal then you can use DMS (Display Manager System). For details of this see The Display Manager System later in this document.

The format of the command to run SAS is:

sas filename

SAS enters the Display Manager System (see below) if the filename is omitted. If a filename is specified SAS expects to read input from the file named 'filename' with the suffix .sas (if the file has a .sas suffix it can be omitted). SAS uses temporary files with the suffix .work which it deletes at the end of the session.

Command line options

The main options control what happens to the log and what happens to the printed output. For details of other options see the manual SAS Companion for the Unix Environment and Derivatives.

The log is a listing of the replies from SAS to your statements, such as the length of time a procedure took, details of how many cases have been read, reports of any errors. The output from any PUT statements also appears in the log.

The printed output is the output produced by the various procedures, for example, tables, means, plots and is sent to the listing file.

By default the log is sent to a file with the suffix .log, the listing is sent to a file with the suffix .lst, and SAS commands are read from a file with the suffix .sas.

The options may be specified on the command line when calling SAS or put into a configuration file called config.sas (see below).

The following is a list of some of the SAS system options:

-log filename
specifies the destination to which the SAS log is written.
-print filename
specifies the destination to which the SAS output is to be written.
-linesize width
specifies the line size of SAS output (75 is a convenient line size for looking at output on a screen).
-pagesize n
specifies the number of lines that can be printed in a page of SAS output (30 is a convenient page size for looking at output on a screen).
-stdio
specifies that the SAS system should use stdin, stdout and stderr. This option tells SAS to take its input from stdin, to write its log to stderr, and to write its output to stdout.

Examples

sas fred
reads a file called fred.sas, sends the log to a file called fred.log and the listing to a file called fred.lst.
sas -log fred regression
reads a file called regression.sas and sends the log to a file called fred and the listing to a file called regression.lst.
sas -print fred regression
reads a file called regression.sas and sends the listing to a file called fred and the log to a file called regression.log.
sas -stdio < myinput > myoutput 2> mylog



File myinput is used as the source program, and files myoutput and mylog are used for the procedure output and log respectively.

Configuration files

The options can be set in a configuration file instead of being specified on the command line. When a SAS session is started, SAS automatically configures itself as specified in the configuration file. SAS looks in various places for this file, including the file .config.sas in your home directory.

Example

Copy the sample configuration file from /large/SAS607.HP/sas/config.sas to .config.sas (notice the leading period) in your home directory.

cd
cp /apps/SAS8.1/sasv8.cfg.config.sas

Edit .config.sas and append the following to the end of the file:

-stdio
-linesize 75
-pagesize 30

Using this configuration file, the following command:

sas < fred > out

takes input from a file called fred, sends output to a file called out and the log is displayed at the terminal.

File handling - the INFILE statement

If data is to be read from a file you must include an INFILE statement to indicate which file is to be read.

For example, if the data is in the file shells.dat, use the SAS statement:

INFILE 'shells.dat';

to tell SAS which file to read.

Back to top

The Display Manager System

Interactive use is via the Display Manager System. Using SAS interactively can be very slow and is often confusing, and so is not recommended.

The Display Manager System is described fully in the manual SAS Language and Procedures: Usage.

Entering and leaving DMS

DMS is invoked when the sas command is given without a filename.

The screen is divided into a program editor screen for inputting and modifying SAS statements, a log screen where the SAS statements are echoed along with the log, and an output screen. When a procedure produces output the whole screen becomes the output screen.

To exit from DMS, give a BYE command from either command line or execute an ENDSAS statement in the SAS program.

Back to top

Keeping SAS data sets

SAS data sets can be stored in permanent files in your directory. The name of a library may be specified in DATA statements before the name of the data set, separated from it by a full stop. For example, SURVEY.PEOPLE means the data set PEOPLE in the library SURVEY. When no library name (and full stop) are given, data sets are stored in the temporary library WORK, which is erased when you leave SAS. The advantage of saving data sets into SAS files is that SAS can read its own files much more quickly than text files which you create with the editor. A LIBNAME statement is also required; the name of the library should be put after LIBNAME, followed by '.' (to put the library in the current directory).

To show how this works, suppose you have done a survey and collected two sets of information, one about people and one about the houses in which they live. The data is in the files people.dat and houses.dat and you want to input them and save them in SAS data sets.

LIBNAME SURVEY '.';
DATA SURVEY.HOUSES;
INFILE 'houses.dat';
INPUT HNUM RATES AREA ROOMS;
RUN;
DATA SURVEY.PEOPLE;
INFILE 'people.dat';
INPUT HNUM PNUM AGE SEX WORKSTAT INCOME QUALS;
RUN;

SAS identifies your use of the library SURVEY and the two members of that library PEOPLE and HOUSES. It creates two files - houses.ssd and people.ssd - which contain the data. If you wish to access this data in a later SAS session simply specify the full name, for example,

LIBNAME SURVEY '.';
PROC FREQ DATA=SURVEY.PEOPLE;
TABLES SEX AGE WORKSTAT;
RUN;

SAS searches your home directory for the PEOPLE dataset.

Back to top

Graphics on Unix

SAS can draw simple pictures on the line printer or terminal (using CHART and PLOT) or high definition graphs on various graphical devices (using GCHART, GPLOT, GCONTOUR, GMAP, GSLIDE, etc). CHART and PLOT are described in the manual SAS Language and Procedures: Usage, and the rest in the SAS Procedures Guide. The local document Practical introduction to SAS on Unix (document sas-t1) describes the simple use of CHART, PLOT, GCHART, GPLOT and GMAP. For information on producing high quality graphics, see Using SAS/Graph on Unix (document sas-r2).

Back to top

SAS sample libraries

SAS provides example programs to demonstrate techniques. These are divided into several libraries including:

base
for items using the base software
graph
for graphics
stat
for statistics

They are stored in the directory /large/SAS607.HP/sas/samples. These libraries are directories. For example, suppose you want to look at npar1ex.sas (non parametric one way examples) in the stat library, type:

cp /apps/SAS8.1/samples/stat/npar1ex.sas .

The example program (npar1ex.sas) is copied to your directory. The program may then be printed, edited etc.

To display the contents of the stat library type:

cd /apps/SAS8.1/sas/samples/stat
ls

This lists the statistics example programs.

Back to top