RUNNING SAS AND VIEWING RESULTS

There are three ways to run SAS --

For the most part in this workshop, we will work with the DMS. But, to introduce you to all four possibilities, we will do brief exercises using command files, line mode, and standard I/O. Some may prefer using command files to using the DMS, but line mode has very limited application.

The SAS Display Manager System (DMS)

The SAS Display Manager System provides a complete interactive environment for running SAS. When running SAS with the DMS, there are three primary screens and numerous additional screens. The three primary screens are --


Running SAS with the DMS

To run interactive SAS with the Display Manager (DMS), type --

     sas &
This command starts SAS using the DMS. Several windows open when SAS initiates.

When you start the DMS you are placed in the program-editor window. To illustrate how to submit a job in the DMS, type the following commands in the program editor:

Proc Contents

The functions of these commands are --

After typing these commands, select "Run/Submit" or press the F3 key to submit the job. Note what happens in the program, log and output windows. (Use F7 and F8, respectively, to move backward and forward one screen at a time, or use the left mouse button on the vertical scroll bar.)

By default, the program window empties. This can be avoided by setting the F3 key to "submit; recall" and using the F3 key to submit jobs.

The Log Window repeats the commands submitted from the Program Editor and adds annotations, including error diagnostics when the program is not correct. The Output Window displays the output from SAS procedures, and sometimes other output.

To print the contents of these windows directly to a UNIX printer, first edit the print properties. Select --

File
Print Setup
Properties (For PostScriptLevel 1)

Go to the "Destination" tab and set it as shown --

Print Setup

The "Destination" dialog indicates to use the UNIX qpr command and route the window contents to a printer queue named smips. This is the UNIX printer in Smith Hall. The names of printer queues for other destinations are listed at the sites, or see the list online.

The SAS help facility is available through the DMS and from a browser. But the browser must originate from a udel.edu IP address.

Before using the DMS version, set your default SAS browser by editing a file in your home directory named .Xdefaults Edit the file using pico --

     pico ~/.Xdefaults

(Remember the meaning of ~/ )Add the following two lines --

SAS.webBrowser: /usr/lib/netscape-launcher
SAS.helpBrowser: /usr/lib/netscape-launcher

To use the DMS version, select Help/SAS Help and Documentation. To access the documentation directly through a web browser, point the browser to http://support.sas.com/onlinedoc/913/docMainpage.jsp and bookmark it.

As an exercise, open the SAS help by selecting the link above. Then select--

Base SAS
Base SAS Procedures Guide
Procedures
The MEANS Procedure

This gives you a summary of the syntax for the means procedure. To exit click the in the upper right corner of the browser or browser tab.

To exit sas, select File/Exit from the Program Editor or type endsas in the toolbox window.

Command file

The sequence for running SAS from a command file is --

  1. Create the SAS commands in a file with an extension of .sas -- root_name.sas. We will use the pico editor to create command files.

  2. Submit the job by typing --

    sas root_name
    Note that you do not need to type the extension in the file name (.sas is assumed)

  3. Review the results - results usually are contained in two files - root_name.log and root_name.lst (listing/procedure output). We will use the pager program called less to review the results. (Note: the first character in .lst is the letter el, not the number one (1).)
The thee main files when SAS is run from a command file correspond to the three primary windows in interactive SAS with the DMS --
Running SAS with a command file ("batch" mode)

To duplicate what we did with interactive SAS, first start the pico editor and type in the same commands as before. To start pico, type --

     pico contents.sas
This is a UNIX command that starts the pico editor and instructs it to edit a file named contents.sas. Enter the following commands in the editor:

contents.sas

Notice that most of the commands for the pico editor are listed at the bottom of the screen. The caret character (^) stands for the control key. It means to press the control key, then the character following ^ and hold them down simultaneously for a moment. ^X, for instance, instructs pico to exit. Before it exits, it asks you whether you want to save the file. Type the letter y. Then press the Enter key in response to the next question.

To illustrate running SAS, type --

  sas contents
  ls
  less contents.log
  less contents.lst
The first command, sas contents, runs sas using the commands in the command file called contents.sas. You don't need to type the extension (.sas), but it will work if you do. The second command lists all the files in your current directory. You should see three files --

  contents.sas
  contents.log
  contents.lst

The first less command displays contents.log. on your screen. The second less command displays contents.lst on your screen. To maneuver through a file using less, use the following keys:

q    quit
<SPACEBAR>, d    Down one full screen
b    Back one full screen
Down Arrow j, Enter    Down one line
Enter, k    Up one line
G    Go to bottom of the file
g    Go to top of the file
/<string>    Search forward for "<string>"
?<string>    Search backward for "<string>"
n    Repeat most recent search going in the same direction
N    Repeat most recent search going in the opposite direction
h    Help (q to exit help)
-i    Toggle case sensitive. First use: ignore case differences in searches. Second use: honor case differences again.
Keys on the same line in column 1 separated by a comma are alternative keys for the same operation. You can go down one screen by pressing the spacebar or the d key, for instance. Some connections to strauss may not support use of the up and down arrows. If they don't work, use the k and j keys, respectively.

There are a finite number of commands to remember here. If you learn them, navigating through a file and finding text is much faster and more convenient than using a mouse.

Do not actually print these files now. If you did want to print them, you would use the print command, qpr. Always print both your .log file and your .lst file, for example --

     qpr -q smips contents.log
     qpr -q smips contents.lst

then fasten them together so you will know what commands generated the output in the .lst file.
 

To speed up the work, open two (or more) windows on strauss. Use pico (or any other UNIX editor) to edit the command file. Run the program and view the output in the other window. Since unix commands can be combined onto a single line by separating them with a semicolon (;), you need type the run and view commands just once. Then bring them back with the up arrow (when running T-shell), like this: Start pico in one window, as before --

     pico contents.sas

In the other window, run the job and view both outpu files at the same time, like this --

     sas contents; cat contents.l?? | less

Running SAS in Line Mode

Line-mode execution of SAS rarely is used. Generally, line-mode execution may be useful if you have few commands, your results will not fill more than one screen, and you do not need a record of the output. Line-mode execution is fast.


Line-Mode Execution

Before starting, there are a couple of points to note --

To run SAS in line mode, type --

     sas -nodms
at your UNIX prompt. This starts sas in line mode, without DMS. Now type in the same program we have run before --

     libname lhsas '~larryh/sasnotes';
     proc contents data=lhsas.gss04; run;
This example illustrates the limitations of the line mode - results flash across the screen so fast they can't be read.

So, line-mode is useful only for small jobs. Try, for example --

     libname library '~larryh/sasnotes';
     proc means data=lhsas.gss04;
       var sex age persinc;
     run;

These results are short enough to be read. Sometimes line mode is useful if you need a number such as a mean or standard deviation to insert into code you are writing. For instance if you want to create a variable which is the square of the deviation of personal income from its overall mean, you might get the mean from an interactive run like this one and plug the result into your SAS program, like this

     persincSq = (persinc-32.9957253)**2;

To exit sas, type --

         endsas;
(Remember the trailing semicolon.)

Running SAS with the stdio Flag

Sometimes it is useful to set the standard I/O flag and pipe commands into SAS. This can be useful for debugging and particularly in cases when a program contains many repeats of the same code with some details changed for each instance. The SAS macro language also is useful for repetitive program code and is used much more often than a script. But macros (IMHO) are difficult to debug.


Elementary example piping commands from a file into sas:

cat contents.sas | sas -stdio |& less 

This strategy can be useful for debugging. You don't write any files until you eliminate all the bugs. And the saslog and listing (procedure output) are interleaved instead of separated into two files. (The ampersand (&) stands for something different here. It stands for the standard-error output device instead of background running.) SAS writes the saslog to the standard-error device (stderr) and the listing to the standard-out device (stdout).