Introduction to SAS

Return to SAS Information


Using the Web Interface to SAS

While SAS can be run interactively, it is still easiest (and safest) to run it in another mode. This section describes an interface to SAS using your web browser, and the next section describes using the Unix "batch" system. The Web interface is what we will use in class since you will not have to learn anything about Unix in order to use it. However, if you find yourself using SAS for other purposes (term paper, honors thesis, etc.) the batch system may be the easiest for you.

In order to use the web interface, you will simply click on the link to "Running a SAS program via the Web Interface." For the homework problems I will have an equivalent link titled something like "Run the SAS job for Assignment 2" right on the page for that assignment. The main page for the course also has a link to the WEb interface.

When the web interface comes up, you will have to fill in two boxes (technically this is an HTML form, but you don't have to worry about that) and click a button to run the job.

The first box is for your netid:

The second box (further down the form) is where you will enter the SAS commands, in the job box:

Further down the form, you will see a RUN button to push to submit your job.

Output File:

Printing Results:


Using SAS on a UNIX System

While SAS can be run interactively, it is still easiest (and safest) to run in "batch" mode. Therefore, you must be familiar with the use of files on your computer system. Basically, a file is like a piece of paper in your notebook or a chapter in a book; a directory is like the notebook or book itself. Here are a few examples of program calls on UNIX, our platform (the prompt % is typed by the computer):

% cp file1 file2        make a copy of file "file1" named "file2" 
% more file             look at "file" a page at a time
                        (use long space bar to page forward)
% ls                    list names of your files in your directory
% ls -l                 long version of "ls" (has dates of last change)
% emacs file            edit "file" using full screen editor "emacs"
% vi file               edit "file" using full screen editor "vi"
% rm file               remove "file" from your directory

While it is more efficient in the long run to learn an editor (emacs or vi) on our sytem, it is also possible to work from your local computer and use FTP to move files back and forth. There are on-line manual pages for commands. For instance, type man rm to find out more about the rm command. There are several good Unix references on the ATS help pages.

The easiest way to run SAS is to store your commands in a file and then pass that file to the sas program. You can either copy one of your instructor's examples, or create your own using emacs or vi. It is a good idea to get in the habit of using the .sas suffix to identify a file of SAS commands. Other standard suffix conventions include:

myfile.sas      sas command file (may have data also)
myfile.dat      data file (if separate from "myfile.sas")
myfile.log      log of what sas did with your commands
myfile.lst      output listing of your successful commands 

The myfile name is up to you; use 8 or fewer characters in the name, starting with a letter (a-z). Numbers (0-9) or underscore (_) can be used, but avoid other symbols. (This naming convention applies to SAS variables and datasets as well.) The sas program automatically produces the myfile.log and myfile.lst files for you. All you have to do is type the command

% sas myfile.sas

Usually it takes a little while to run. If instead of giving your file you simply typed

% sas

the computer goes into "interactive mode". This is rather complicated and best left to advanced (or adventurous) users. Avoid for now. If you do type this by mistake, simply type the following:

   ;endsas;

(Those are semicolons, the key just to the right of the L key. Follow by a RETURN.) This will get you out of SAS safely. Otherwise, yell for help!

NOTE: Always review the log file before looking at the output listing. It is usually short. Lines with NOTE: are fine and can be helpful in tracing transformations and creation of new variables. Lines with ERROR or WARNING should be heeded: look for the problem somewhere ABOVE the identified line.


SAS Language

Examples of SAS can be found The myfile.sas usually contains three kinds of sas "paragraphs" or "steps", namely:

options         printer options
data            data input, transformation and manipulation
proc            procedures for plotting, regression, etc.

The options, data steps and some procs (numerical and graphical summaries, plots) are described in the SAS/BASICS book. The other procs (regression, analysis of variance and other fancy stuff) are found in SAS/STAT. SAS reads your file in "free" format--use as many spaces or tabs as you like--but requires a semicolon (;) at the end of each "phrase" or "sentence". It is good practice to indent phrases in data or proc "paragraphs" for ease of reading.

Comments can appear anywhere in your program EXCEPT in the middle of data. Comment lines can begin with an "asterisk (*). Alternatively, a comment paragraph can be surrounded by "slash asterisk" (/*/*) and "asterisk slash" (*/).

* this is a comment line
/* this is also a comment line */

OPTIONS can only appear as the first line of myfile.sas. Here is a setup for looking on the screen:

options nocenter linesize=80 pagesize=24;

Nice size printer plots do better with the option pagesize=50. Common options include:

   nocenter     do not center output (flush right instead)
   linesize=80  set width of page to 80
   ls=80        same as linesize
   pagesize=50  set length of page to 50
   ps=24        same as pagesize