SAS on the CUNIX Cluster


Abstract
This document is a guide to using SAS on the cunix cluster.
For assistance with getting started writing a SAS program, see the document What You Need to Know to Write a SAS Program.

  1. SAS in Batch Mode

    In batch mode, SAS commands or statements are executed from one file, with the file
    extension sas, and output directed to two other files with the same name as the input file,
    but with the file extensions log and lst. The SASLOG (.log) file contains notes and messages
    produced by the program and the SAS Listing (.lst) file contains output from SAS procedures
    that produce printed results.

    To work in batch mode, first create a file of SAS statements, or a program, with
    a UNIX editor. The following editors are available:

    Pico is a menu-based editor and the easiest to use. To start it up, type pico at the $ prompt.

    SAS Statements

    SAS statements are free format but must end with a semicolon (;). Following is a sample
    program which is simply a file with a series of SAS statements. This program reads raw data
    from an external file and creates a SAS dataset. An explanation for each SAS statement follows:

       options linesize=78 nocenter;
       filename rawin disk "test.dat";
       libname sasdata "~me1";
       data sasdata.test; infile rawin;
            input idnum $ 1-3 sex 30 status 39;
       run;
    
    
    options linesize=78 nocenter;   Sets page width to terminal size.
    filename rawin disk "test.dat";   Gives name and location of raw input data.
    libname sasdata "~me1";   Designates the directory me1 to save the SAS dataset in
    data sasdata.test; infile rawin;   Start reading the raw data. The two-part name means save the SAS dataset permanently
    input idnum $ 1-3 sex 30 status 39;   Defines the data
    run;   Executes the SAS statements

    Then this program reads the newly created SAS dataset and runs frequencies on several variables:

       options linesize=78 nocenter;
       libname sasdata "~me1";
       proc freq data=sasdata.test; 
       tables sex status;
       run;
    
    Running SAS in Batch

    After creating a SAS program, run it by issuing the command:

       sas filename.sas
    

    at the UNIX prompt (where filename.sas is the name of your SAS program file).
    Note that sas is in lowercase letters. Typing the sas extension is optional.

    Output in Batch Mode

    After the job completes, you should begin by checking the saslog. SAS does not display
    warning or error messages on your screen as it runs, but sends them to the .log file.
    Do not assume your program ran correctly just because no messages appeared
    on the screen. Check your .log file for error messages by typing

       more filename.log
    

    or by bringing the file into an editor.

    Output from SAS procedures will appear in your .lst file, which can be viewed by typing the
    UNIX command

       more filename.lst

    or by bringing the file into an editor. If there is a problem with your program, bring it back
    into your editor, make corrections, save it, and run SAS again. If you are still stumped,
    send e-mail to eds@columbia.edu with the log file and we will try to help.


  2. Running Interactive SAS in X-windows

    To run in interactive mode, you must run in the X-windows interface. If your display variable has
    already beendefined, simply type
       sas

    with no arguments. Otherwise, you must define and export the display variable by typing
    the following command at the UNIX prompt:

     
       export DISPLAY=terminal.cc.columbia.edu:0

    where terminal.cc.columbia.edu is the name of your X-terminal, e.g., carman3.cc.columbia.edu.

    In X-windows, there are three default windows:

    • Program Editor Window
    • Log Window
    • Output Window

    Your program statements are typed in the program editor window. You need to include a SAS run; command to have statements execute. To submit your statements, pull down the Locals menu and select Submit (or click on the run icon, which is a picture of a man running).

    In interactive mode, messages and error statements appear in the log window. Output is directed to the interactive output window. Note: output in interactive mode is not automatically saved to files; you have to remember to do this yourself if you want to save your log or output.

    SAS File Name Conventions
    • Programs: You can use any name for the file of SAS program statements, but the file extension should be sas, e.g.
           hmwk1.sas
           gss91a.sas
      
    • Raw Input/Output: Any UNIX path name plus a file name enclosed in quotes can be
      used on theSAS filename command, e.g.,
         filename rawin "test.dat"; 
         filename hwdat "~/data/wk12.dat"; 
         filename pums
         "/eds/datasets/pums90/puma-washington-hts-5pct.samp";
      
    • SAS Datasets: These are written to the directory indicated by the libname command.
      Any UNIX path name enclosed in quotes can be used. You can also use "~/" for your
      home directory or "." for the current directory, e.g.:
         libname sasdata "."; 
         libname sasfile "~/sasfiles"; 
         libname sassets "/scratch/me1";
      

      Note that the libname name does not appear as part of the name of the SAS dataset
      in your unix directory. For example, the SAS dataset created in the first example will
      appear as test.ssd01 when you type the UNIX ls command.


  3. Hints for Working with SAS in UNIX and X-windows

    • Running Jobs in the Background: To avoid tying up your terminal while running a SAS batch job, run it in the background by using the unix & option:

         sas test &

      You can now do more work while SAS is working away elsewhere. You will see a message like this:

          [2] + Done sas test &

      when the job is finished. You can check on the job while it is running, with the UNIX jobs command.

    • Using the Scratch Directory: If you are writing a very large SAS dataset, you might
      need to write it to the temporary directory "/scratch." You can use the "mkdir"
      command to make yourself a directory here
         mkdir /scratch/me1 
    • Long Record Lengths: For raw data with a record length of over 256 characters you
      have to declare the "lrecl" on the filename statement:
         filename rawin "gss91samp.dat" lrecl=2960;
    • Reading Compressed Files: If your raw data is compressed in either gzipped or zipped format (i.e. with the extension .gz or .Z) SAS can read it directly using zcat in the pipe command.
         filename indata pipe "zcat huge.dat.gz";
    • Lost Windows: If you accidentally close a window in interactive mode, you can get it
      back by choosing the appropriate name under the Globals menu.