Controlling the SAS Environment

Controlling the SAS environment is divided into three subtopics:

SAS options

Automatic execution of SAS commands

Customizing Your Interactive SAS Session

SAS options

You may set SAS options in several places. Here are eight of them:

  • options statement in a command file or submitted in an interactive session
  • autoexec.sas   file in your current working directory
  • autoexec.sas   file in your home directory
  • command-line flag
  • SASV9_OPTIONS    environment variable
  • sasv9.cfg    in your current working directory
  • sasv9.cfg    in your home directory
  • .sasv9.cfg   in your home directory (hidden file)

SAS searches for the options in the order given and uses the first one it finds. However, if conflicting values are given in one location (e.g., the same config file), the last setting is used.

Some options are set before SAS initializes and cannot be changed during the SAS session. Other options may be changed at any time. Any option can be specified in a config file, on the command line, or in the UNIX environment variable, SASV9_OPTIONS. These take effect before SAS initializes. Only options that may change during a SAS session can be specified elsewhere. The SAS documentation indicates where each option can be specified.

For example, suppose you want the number of characters per line in the SAS log and SAS listing files limited to no more than 80 and want to prevent overprinting of characters in error messages. To do this only in your current job, place an options statement at the top of the command file

options ls=80 noovp;

The noovp option stands for no overprint. It makes error messages much easier to read and interpret when viewed on your terminal screen. It also prevents bold printing of error messages when the SAS log is printed on paper. But the noovp option is irrelevant in an interactive SAS session and has no effect.

To accomplish the same settings using command-line flags and a command file named dataprep.sas, type

sas -ls 80 -noovp dataprep

at the UNIX prompt.

The syntax for setting a UNIX environment variable depends on the UNIX shell you are using. Most users at the University of Delaware use the csh or tcsh shell. The syntax for these two shells is the same. Use the setenv command. For example, to set the linesize and noovp options, type

setenv SASV9_OPTIONS '-linesize=80 -noovp'

at the UNIX prompt.

These settings remain in effect as long as the environment variable is set with their values, generally for the duration of your UNIX session. Environment variables also may be defined in a file named .localenv which is located in your home directory. Commands in the .localenv file are executed automatically when you begin a UNIX session.

To apply these options to all your SAS programs, put the options statement in a file called autoexec.sas in your home directory, or place the following two lines in a sasv9.cfg file (or .sasv9.cfg) in your home directory:

-linesize 80
-noovp

For a complete list of SAS system options, see the SAS Language Reference.

Top

Automatic execution of SAS commands

You also may execute SAS commands automatically at the beginning of each SAS session by placing the commands in an autoexec file. The autoexec file must be named autoexec.sas and placed in your current working directory or in your home directory. An autoexec file in your current directory takes precedence over one in your home directory.

For example, suppose you are using the 1972-2004 General Social Survey data. You have made a subset of the data and placed it in a SAS data set located in a subdirectory of your home directory called gss4295 (4295 is the ICPSR study number). You wish to use the libref method of referencing the data. You may place the following libname statement in an autoexec.sas file:

libname gss4295 '~/gss4295';

This will save you the trouble of typing the libname statement in all your programs to analyze these data. For example, suppose you called the SAS data set gsswork. Then you can read the data with the reg procedure using following statement:

proc reg data=gss4295.gsswork;

If you want to access this file from several directories, put the autoexec.sas in your home directory. But if you will be doing all your work with these data in one or two directories, put the autoexec.sas file only in the directory(ies) where you will be doing the work.

Since you may include options statements in an autoexec.sas file, you may not need a sasv9.cfg file if you have an autoexec.sas file. The autoexec is more general, in that you may include options and SAS statements. But it is less general for specifying options.

Top

Customizing Your Interactive SAS Session

You may customize resources such as colors, fonts, and whether to start the Display Manager (DMS) with the pmenu buttons or command lines. Many of the options may be set from the Tools menu by clicking Options then clicking Preferences after starting an interactive SAS session with the DMS, as shown in Figure 1.

Tools
Figure 1.

A few options are noteworthy. The Keys option brings up a new window displaying commands to which function keys and other keys are assigned. This window is a useful reference for learning shortcuts around using the mouse. For example, the F3 key, by default, submits the SAS program currently in the Program Editor window. You may change the key settings by typing the desired SAS DMS command beside a key name and then saving from the file menu. The Turn All Menus Off option causes the DMS to display a command line instead of the menus. You may type commands at the command line. Some users may find the Toolbox to be a nuisance. By default, it's always on top. You can edit its behavior or turn it off from the Options menu.