SAS Training and Documents

Welcome to CAPS SAS Training & Documents page. Below is information for CAPS online training.

This training is designed to cover four topics. It is not meant to teach you everything that there is to know about these subjects; this is just a kick-start to get you going!

  1. The SAS System software suite contains a wide variety of software products (called SAS for short) that create an all-encompassing data-driven environment. SAS is the “Swiss army knife” of the statistical analyst covering the wide-spread areas of data processing, statistical analysis, graphing, Geographic Information Systems (GIS), Relational Data Bank Management Systems (RDBMS) access and much more. SAS is a combination of high-level, optimized PROCs (a Fourth Generation Language or 4GL) and low-level DATA step programming (a Third Generation Language or 3GL).
  2. UNIX/Linux is the operating system of choice for SAS use due to its stability and security.
  3. Emacs is a powerful editor and, with the Emacs Speaks Statistics (ESS) package, is tightly integrated with SAS.
  4. The last topic involves the details of our local setup here at CAPS.

Introduction to SAS - Slide Presentation (PDF)

Basic SAS - Handout (PDF)

Example (PDF)

SAS Documentation

Training Session 1: Unix/Linux, Emacs and ESS (PDF)

Training Session 2: Introduction to SAS, SAS Macros and Warehousing (PDF)

Training Sessions 3 and 4: Introduction to SEER, Medicare and SEER-Medicare (PDF)


How do I set up a new user account?

Please contact Rodney Sparapani at 955-8786 or

How to customize my shell environment?

The original shell environment, sh, is called the Bourne shell, but few people use it anymore except in sh scripts. Several later shells were developed that are more user-friendly, but not as widely available. The Korn shell, ksh, and the Z shell, zsh, are compatible with the Bourne shell, but the original C shell, csh, and the TENEX C shell, tcsh, are not. zsh supports sh by being compatible with the Bourne shell, supports ksh extensions to the Bourne shell and supports many of the convenient features from csh/tcsh. Therefore, zsh is what we use since sh/ksh scripts are more common than csh/tcsh scripts, yet csh/tcsh users should still find their favorite features.

In ~/.zshrc (when you type the ~ character, it expands to your HOME directory), you can set up your own personal environment, such as creating aliases. For example, the default alias for xemacs is:
alias xemacs='run-with-aspell xemacs'

You may want to modify that for your big 24.1 inch LCD monitor:
alias xemacs='run-with-aspell xemacs -geometry 200x68'

How can I run a binary or script program?

Those who are familiar with other operating systems like DOS/Windows or Mac may not be familiar with Unix file permissions. If the file permissions are set incorrectly, when you attempt to run a binary or script named PROGRAM, you will get an error message:
prompt> PROGRAM
Permission denied: PROGRAM

The reason is most likely that the executable permission setting is in the off position. To check, type:
prompt> ls -l PROGRAM -rw-r--r-- 1 user pcor 603244 Nov 17 13:24 PROGRAM

The fourth character, '-', indicates that the executable permission setting is off. To turn the executable permission setting on, type:
prompt> chmod +x PROGRAM

And to verify, type:
prompt> ls -l PROGRAM -rwxr--r-- 1 user pcor 603244 Nov 17 13:24 PROGRAM

Now, you see that the fourth character, 'x', indicates that the executable permission setting is on and you can execute it successfully:
prompt> PROGRAM

For more information on setting Unix file permissions, type:
prompt> man chmod

How do I delete control characters from a text file?

The tr command allows you to delete characters from a text file as follows:
prompt> tr -d CHARACTERS < input > output

The way you specify CHARACTERS is very flexible. For example, all upper case letters would be '[A-Z]', all lower case letters '[a-z]' and all numbers '[0-9]'. For control characters which are non-printing characters, you specify them by their octal representation: 

Control Character Name Octal Representation
^@ NUL \000
^A SOH \001
^B STX \002
^C ETX \003
^D EOT \004
^E ENQ \005
^F ACK \006
^G BEL \007
^H BS \010
^I HT \011
^J LF \012
^K VT \013
^L FF \014
^M CR \015
^N SO \016
^O SI \017
^P DLE \020
^Q DC1 \021
^R DC2 \022
^S DC3 \023
^T DC4 \024
^U NAK \025
^V SYN \026
^W ETB \027
^X CAN \030
^Y EM \031
^Z SUB \032
^[ ESC \033
^- FS \034
^] GS \035
^^ RS \036
^_ US \037

To delete all of the control characters (except the necessary ones), you would do the following:
prompt> tr -d '[\000-\010\013\015-\037]' < input > output

If you know that the file you are dealing with is an MS-DOS file and all you need to do is delete CR, see next question/answer.

How do I convert a DOS/Mac file to a Unix file or vice versa?

The tr command allows you to convert characters from a text file as follows (see also Q6.):
prompt> tr FROM-CHARACTERS TO-CHARACTERS < input > output

The way you specify FROM-CHARACTERS and TO-CHARACTERS is very flexible. For example, all upper case letters would be '[A-Z]', all lower case letters '[a-z]' and all numbers '[0-9]'. If all you need to do is convert a text file from DOS/Mac to a Unix file (or vice versa), then you only need to be concerned with certain control characters (which are non-printing characters), that you specify by their octal representation:

Control Character Name Octal Representation Purpose
^J LF \012 Unix end-of-line
^M CR \015 Mac end-of-line
^M^J CRLF \015\012 DOS end-of-line

To create a Unix text file from a DOS text file, delete the CRs:
prompt> tr -d '\015' < input > output or use the dos2unix command: prompt> dos2unix input output

To create a Unix text file from a Mac text file, change the CRs to LFs:
prompt> tr '\015' '\012' < input > output

To create a DOS text file from a Unix text file, requires the unix2dos command:
prompt> unix2dos input output

To create a Mac text file from a Unix text file, change the LFs to CRs:
prompt> tr '\012' '\015' < input > output

How can I find my big files?

The easiest way is with the script which finds the biggest files on a local file system.  If you want to find the biggest files in the $HOME tree, then you need to run the script from buz:
buz% ~

This will create a list of your biggest files so you can remove or gzip them.

How can I clean up my nuisance files?

There are two scripts to clean up your nuisance files:
rmclean, which removes them, and gzclean, which gzips them.

For example, to see all the nuisance files in the directory tree foo, type:
prompt> rmclean -all -test foo

To delete them, type:
prompt> rmclean -all foo

To gzip all the nuisance files in the directory tree foo, type:
prompt> gzclean -all foo

For more information, type:
prompt> rmclean prompt> gzclean

How can I secure my files and directories?

There are several Unix commands that can be used to secure files and directories such as chgrp, chmod and umask. Check out the man pages of these commands for more information. Be aware that it is extremely easy to use these commands incorrectly. So, the grpthink command has been created that will secure a directory and all of its files and sub-directories. For more info, type:
prompt> grpthink -h

How do I 'do-loop'?

In all Bourne-compatible shells, like sh, ksh, zsh and bash, you can loop over a list of files very easily, such as:

prompt> for i in *.txt
prompt> do
prompt> echo $i
prompt> cat $i
prompt> done

In the case where you are only have one command to repeat, in zsh this can be shortened too:

prompt> for i in *.txt
prompt> cat $i

If you want to loop over some integers, its kind of messy in sh or ksh. However, in zsh and bash, it is conveniently similar to C syntax:

prompt> for ((i=1;i<=5;i++))
prompt> do
prompt> echo $i
prompt> done

And, in zsh, it can be written even more concisely:

prompt> for i in {1..5}
prompt> echo $i

How do I change my password?

There are two commands to change your passwords.  The first command is for your Unix account, type:
prompt> passwd

Of course, you need to know your current password to make a new one. To see the details of the passwd command, type:
prompt> man passwd

That may not work very well if you are running XEmacs; if so, then:
M-x man Enter and you will be prompted for the name of the command in the minibuffer.

Similarly, the command to change your password for file sharing is:
prompt> smbpasswd

How do I transfer files?

When you want to transfer files between Unix and Windows, the easiest way is to create a network drive on your PC. When you are in an Explorer window such as My Computer, select the Tools menu and choose Map Network Drive. This will bring up a dialog box. You can choose a Drive letter (Z: is the easiest). Then specify the Folder by \\SERVERNAME\USERNAME.

Unless you need to do this all the time, make sure that Reconnect at logon is unticked and then click Finish. You will be prompted for your Unix username and your password (see changing your file-sharing password). Supply them and press OK. This should open a window with your Unix HOME directory. You can transfer files by dragging them to or from this window.


How do I run SAS?

Most likely you are using XEmacs to edit your .sas file. If so, then there are some very nice features for running SAS; see the "ESS Commands" towards the end of the first question under XEmacs for more information.

Otherwise, you can run SAS from the command-line:
prompt> nohup nice sas ROOT &where ROOT is the filename without the extension, i.e. the filename is actually "nohup" keeps your command running after you logoff and "nice" tells SAS not to hog all of the resources since you and others may want to run other commands as well.

SAS runs SAS v. 9.2 (the only version of SAS available on Godzilla) and it backs up files with the following extensions, if they exist, before running SAS: .sas, .log, .lst, .txt, .rtf, .ps, .eps, .pdf, .jpg, .jpeg, .gif and .tiff. Up to nine different versions of each file are supported; is the most recent, is the second most recent, etc.

This SAS script attempts to detect if you are running the same SAS program multiple times.

Where did the SAS documentation go?

SAS once again provides its documentation in HTML and PDF form. View SAS documentation

PostScript/Encapsulated PostScript with SAS v.9

In SAS v. 9, you may experience problems with PostScript and/or Encapsulated PostScript files that have no linefeeds. There is a simple solution; specify the GEND= parameter as follows: GOPTIONS DEVICE=... GEND='0D0A'X;

SAS Macros

SAS Macros for BUGS Documentation (PDF)


Installing SAS Macros (PDF)

SAS Help

Rodney Sparapani, PhD

Assistant Professor, Institute for Health & Equity and Biostatistics

(414) 955-8786