SAS for Linux

ALERT!
ALERT! As of 1 May 2017, all of this topic is obsolete. It is being left here for reference purposes. See SasVumc for current information.
ALERT!

Introduction

The SAS system is an integrated applications system. The system's analysis tools range from simple descriptive statistics to advanced statistical design. The data presentation capabilities range from simple lists and tables to multi-dimensional plots and high-resolution graphics. It also has procedures for data entry, high-resolution graphics, matrix manipulations, a macro language, and many other features...wait

We all know about SAS and what it can do. We also know that we'd rather be using R or Stata or something else, but whether it is an existing program that must be run or some requirement from a collaborator, SAS sometimes becomes the tool of the moment.

The purpose of this presentation is to describe how to use SAS on the Linux operating system. It is assumed that you know how to program in SAS and use SAS for statistical analyses so we won't be talking about that. What we will talk about are some of the hints and tricks, settings and options that are helpful in running SAS in our workstation environment.

SAS is a big and sometimes confusing system. There are often many ways to do a particular task. The procedures discussed in this talk have proven to work for the presenter, but others may have other ideas. Feel free to suggest those other ways during the presentation and to add them to this page.

SAS configuration options

In certain situations, some of the default SAS configuration options are set too low for long running jobs and jobs that use a lot of memory, but not always. If SAS runs OK for you then there is no reason to change the configuration. I use the file ~/.sasv9.cfg to adjust things to my liking. This file is read when SAS is started. Here is an example.
-nonews
-work /home/vunetid/sas_work_files
-memsize 2048M
-sortsize 1024M
-nocenter
-linesize=90
-pagesize=62
-helpbrowser sas
-xrm 'SAS.helpBrowser: /usr/bin/firefox' 

Running SAS interactively

We can run SAS interactively by typing the command sas at the console prompt. SAS may also be run in a non-windowing mode by using the command sas -nodms.

Running SAS in noninteractive mode

In noninteractive mode users prepare a file containing SAS statements to be submitted for processing. When processing is complete SAS creates one or more files containing output which may be printed and/or viewed. Batch mode processing is useful for large, time consuming SAS jobs, and for repetitive SAS jobs which have been tested.

To invoke SAS in noninteractive mode, you must specify a filename in the SAS command. For example, if "simulation.sas" is the file containing the SAS statements to be executed, and you don't want to specify any system options, the command would be

$ sas simulation.sas

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 simulation.sas &

SAS creates a .log file and a .lst file that contain the log and procedure output.

Running SAS as a batch job

Long running jobs need to be run as batch jobs. See http://en.wikipedia.org/wiki/Batch_processing for more information. Running as a batch job allows one to start the job and then do other things or log off the computer while the job continue to run. Otherwise the SSH connection will eventually time-out and kill your process and hence your job.

You can also submit your program to the batch queue. To do so, you would use the at, nohup, etc. commands. For example, you could submit simulation.sas from your shell prompt as follows:
$ at 2am
warning: commands will be executed using /bin/sh
at> sas simulation
at> <control-D>
job 9 at Tue Mar 27 13:29:00 2007
$
The job will begin at 2 A.M. and SAS will send the output to a file that has the same name as the program and an extension of .lst, and the log goes to a file with an extension of .log. Both of these files are written to your current directory.

It is handy to make a little command file that contains the command to run your program. Then you can use a single command line to submit the job to the batch queue to be run.

Say I have a file called do_sas.sh that contains these lines:
#!/bin/sh
cd /home/dalep/sas_test
sas simulation.sas

This file has to be made executable:

$ chmod o+x do_sas.sh

I can then submit my job with this command:

$ at 2am < do_sas.sh

If you want the job to run immediately, you can use the command "at now".

$ at now < do_sas.sh

The batch command is like the at command except that the batch command run the job at a lower priority so that it won't interfere with whatever else the computer is doing. Refer to the man pages for these commands for more information on submitting jobs to the batch queue.

Change how SAS produces output

Later versions of SAS (9.3 +) by default produce HTML output. For those of us more familiar with plain text output this is unwanted. To change settings so that plain text output is produced, do the following:

  • Run SAS
  • Click on the Tools menu and then click Options
  • Click on the Preferences... item
  • Click on the Results tab
  • Make sure "Create Listing" is selected and that "Create HTML" is unselected
  • Click OK

Using nice to reduce SAS's impact on performance

Another way to run a SAS job so that it doesn't interfere with other interactive use is with the nice command. The nice command lets you run a command at a priority lower than the command's normal priority. The nice value can range from 0 to 39, with 39 being the lowest priority. We can run our simulation job at a reduced priority with a command like this:

$ nice --adjustment=15 sas simulation.sas &

On KDE (the windowing system used on our workstations) there is a handy tool called KDE System Guard that can be used to reduce the priority of running jobs. Invoke System Guard by typing ctrl-esc and right click on the appropriate process name. One of the options will be "Renice Process...". Set the priority to a higher number to reduce its priority.

Online help and documentation on the web

The easiest way to get SAS documentation is on the web. The URL for SAS documentation is

http://support.sas.com/documentation/

Linux specific information can be found in the "Base SAS" section under "Operating Environment Specific Information". Select the "SAS Companion for UNIX Environments". Of particular interest is the section called "Getting Started with SAS in UNIX Environments" which contains much of the information being discussed in this presentation.

Make sure SAS remembers your configuration changes

For some reason, SAS is not set to remember your configuration modifications when the program exits. You can change that behavior like this:

  • from Tools menu choose Options and then Preferences...
  • in the Preferences dialog box click the DMS tab
  • in the Display Manager section, make sure that "Save Settings on Exit" is selected

To select browser for online help

SAS uses a web browser to display its online help. You might need to change which browser is used.

  • from Tools menu choose options – preferences
  • on the Preferences dialog box click the DMS tab
  • in the box for "Help & Documentation Browser – Browser path", type: /usr/bin/firefox (or whatever the correct command is to invoke your favorite browser (how do I determine the command that runs my browser?))
  • Click OK to close the Preferences window.

You may also have to add these lines to your ~/.sasv9.cfg file:
-helpbrowser sas
-xrm 'SAS.helpBrowser: /usr/bin/firefox' 

Fixing program editor behavior

SAS has an unusual default behavior for selecting and copying text. The default is to automatically copy selected text into the paste buffer. A side effect of this is that the selected area immediately jumps back to the unselected state when selection is finished. To change this behavior follow these steps:

  • Tools...Option...Preferences, Editing Tab
  • Set the Default paste buffer to XCLIPBRD
  • and unselect the "Automatically store selection" item

Fixing this setting will allow you to highlight and execute selected lines in the Program Editor.

This is also the place to change the default overtype vs insert behavior. I like the editor to be in insert mode by default so I make sure that Insert is selected in the Cursor section.

Most of use are more comfortable using ctrl-c and ctrl-v as short cuts for copy and paste. You can set SAS for Linux to use these short cuts in the SAS:KEYS window (go to Tools...Options...Keys). In this window enter store on the ctrl-c item and paste on the ctrl-v item. Notice that there is no place to define ctrl-x as a short cut (anyone know how to get around this?), but that ctrl-k is defined as cut. Go to the File menu and select save to save your changes.

SAS Interactive Environment

When you first start SAS software, the five SAS windows are open: Explorer, Results, Program Editor, Log, and Output.

In the Explorer window, you can view and manage your SAS files and create shortcuts to non-SAS files. Use this window to create new libraries and SAS files; open SAS files; and do most file management tasks such as moving, copying, and deleting files.

In the Program Editor window, you enter, edit, and submit SAS programs. To open a saved SAS program file, click the File menu of the Program Editor and choose Open. Select the file to open.

The Log window displays messages about your SAS session and any SAS programs you submit.

In the Output window, you can browse output from SAS programs you submit. The Output window is positioned behind the Program Editor and Log windows. You will need to move the other windows out of the way to see it.

The Results window helps you navigate and manage output from SAS programs you submit. You can view, save, and print individual items of output. The Results window is positioned behind the Explorer window. You will need to move the Explorer window to see it.

Editing in the Program Editor

The program editor is a pretty basic editor. You might want to use a more full function editor along side SAS and just copy and paste chunks of code into the program editor for testing and running. In the program editor, you can use copy and paste and you can highlight and run bits of code selectively.

The program editor may delete your code when you submit your job. Here is how to change that behavior:
  • Click Tools, then Options, and then Program Editor...
  • Click on the Editing tab
  • Unselect the "Clear text on submit" item
  • Click OK

Why did SAS say "The requested information could not be displayed because the connection to the remote browser server failed"?

This is one of the idiosyncrasies of running SAS on Linux. By default, SAS 9.3 and above want to produce their output in HTML format. To do so, there must be a browser running and SAS must be able to find it. That is to what they are referring in the message that says "The requested information could not be displayed because the connection to the remote browser server failed".

If you follow the instructions in the error message you can copy the URL provided into a browser and get instructions for downloading, installing, and running the remote browser server.

If you don't care about HTML output then you can just turn it off. To do so in SAS, click on Tools, then Options, and then Preferences...Then click on the Results tab and make sure that "Create Listing" is selected and "Create HTML" is not selected. Exit and restart SAS and it should then work.

Credit

Some of this presentation is based on "Statistical Software at UMass", accessed on 26 March 2007. See http://www.umass.edu/statdata/.

See also the online SAS documentation: http://support.sas.com/documentation/onlinedoc/index.html
Topic revision: r16 - 05 Jun 2017, DalePlummer
 

This site is powered by FoswikiCopyright © 2013-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Vanderbilt Biostatistics Wiki? Send feedback