SAS on the Unix Server


Koti is a central Unix server available for researchers at VCU.

The current release of SAS available on Koti is SAS 9.4 TS1M5.

Running SAS

When you are logged in to Koti, you can run SAS in batch mode or interactive mode, as discussed below.

(Note:  If you have SAS installed on your PC, you can also use SAS/Connect to run SAS programs on Koti, without directly logging in to Koti.  How to use SAS Connect is not discussed in this document.  Please see How to use SAS/Connect with Koti.)

  • Batch mode:

    When you use SAS in batch mode, you issue a command at the Unix command prompt to instruct SAS to execute a SAS program that is contained in a text file (for example, a text file named "") that is stored on Koti.  While the program executes, you normally you do not see anything displayed on the screen, unless there are severe errors.  When it finishes execution, you receive another command prompt.

    During execution, SAS produces a log file in the current directory.  The log file name is based on the program file name (e:g., "myprogram.log").  If the program produces any output, SAS also creates a listing file in the current directory, which contains the output results.  The listing file name is also based on the program file name (e:g., "myprogram.lst").  If you execute the program again, these log and listing files will be overwritten with the new results (without warning!).

    To run SAS in batch mode:

    • Login to Koti.
    • When you receive a command prompt, type the 'sas' command, followed by the name of your SAS program file (e.g., and press Enter, for example:


  • Interactive mode:

    To be able to run SAS in interactive mode, you must login to Koti using an X Windows program, such as X-Win32 or MobaXterm.

    To launch SAS in interactive mode, you issue just the 'sas' command (with no filename afterward) at the command prompt.  Several SAS windows will open on your PC screen, similar to the windows that are displayed when you launch SAS on a Windows PC (a program editor window, log window, output window, etc.).  You then use your mouse and keyboard to interact with SAS.

    When finished with your SAS session, close all these windows   Note that if you 'exit' the SAS Program Window, all the other SAS windows will also close.

Naming Conventions In SAS

Filename Extensions in SAS:

  SAS dataset file: filename.sas7bdat
  SAS program file:
  SAS listing (output) file: filename.lst
  SAS log file: filename.log


Conventions for Libname Statements within SAS:

LIBNAME Yourlibname  '/home/jdoe/myfolder';

  • The standard SAS libname statement.
  • The full path of desired directory is within quotes.
  • Yourlibname is a libref (nickname) for the /home/jdoe/myfolder directory.

LIBNAME Yourlibname  '~/ProjectLocation';

  • The tilde character '~' represents your home directory.
  • Yourlibname is a libref for the ProjectLocation directory, located within your home directory.

LIBNAME Yourlibname  '.' ;

  • The period  '.' represents your current directory.
  • Yourlibname is a libref for the current directory.

How To Create And Run A Batch SAS Program On Koti

Below are Unix commands to create a directory in your account, change your working directory (i.e., navigate) to that new directory, create and run a SAS program there, and view the results.  It is assumed that you have logged in to your Koti account.  The ">" symbol displayed below represents the Unix command prompt (which will likely be different in your Koti account).

1. Create a sub-directory, named 'project', in which to keep your SAS files.   > mkdir  project
2. Change your working directory (i.e., navigate) to the 'project' directory. > cd  project
3. Display your current directory on the screen (print working directory). > pwd
4. Create a SAS program file using a text editor, such as nano, vi., or emacs (you may want to view YouTube tutorials on how to use these).  This example launches the nano editor to create a SAS program named "".  When using the nano editor, after you finish typing and editing the SAS program, press Ctrl-x to save the program file and exit the editor.  Remember that, in Unix, filenames are case sensitive! > nano
7. Submit the SAS program to run in batch mode.  SAS will create a log file named "sasdemo.log" and, if any output is produced, a listing file named "sasdemo.lst".

Note:  If the batch SAS program you submit to Unix will run for a substantial period of time, you can submit it to run in the background (see below).

> sas
8. Issue the 'ls' command to list the files in your current working directory that begin with 'sasdemo' (the '*' is a wildcard character that matches any characters).  You should see the '' file listed, the 'sasdemo.log' file (created by the above 'sas' command), and the 'sasdemo.lst' file (if the 'sas' command produced any output).  If you include the '-l' option, more information about the files will be displayed (modification time, file size, etc.).  To list all the files in the directory, issue just 'ls' or 'ls -l' (with nothing afterward). > ls  sasdemo*
> ls  -l  sasdemo*
> ls
> ls  -l
9. Use the Unix "less" command / facility to view the contents of your SAS log file and your SAS listing/output file (if one was created).

While viewing a file within "less", here are commands for navigating within the file:

  • Press f to go forward one screen
  • Press b to go backward one screen
  • Press q to quit the "less" facility and return to a Unix ">" prompt.
> less  sasdemo.log
> less  sasdemo.lst
10. Move (rename) your 'sasdemo.lst' file to 'abc.lst'.  You may want to do this before re-running your '' program (which would overwrite an existing 'sasdemo.lst' file).  If the new filename contains spaces, it must be enclosed in single or double quotes. > mv  sasdemo.lst  abc.lst
11. Remove (delete) your 'sasdemo.lst' file (or any file).  If desired, you may specify multiple filenames, separated by spaces, to be removed. > rm  sasdemo.lst

Submit A SAS Program To Run In The background

If a batch SAS program will run for a substantial period of time, you may want to submit it to run "in the background," so you don't have to wait for it to finish.  To do so, simply add an ampersand '&' at the end of the command:  (You can do this with any command or program that you want to run in the background if the program will not prompt you to enter input from the keyboard.)

  • For example, if you have a long running program named "", you could issue this command:

    > sas  &

  • After you press Enter, another ">" command prompt will immediately appear.  At this point, you can issue other commands or even logout, as desired.  Meanwhile, your SAS program will continue to run in the background.
  • When the program eventually finishes, and if you are still logged in, a message will display stating that the program is "Done".  This message only appears when you receive a new ">" command prompt (for example, just after you have issued some other Unix command).  Also, you will not receive this message if you have logged out and logged back in.
  • If you have programs (also known as "jobs") that are still running in the background, and you have not logged out since you launched them, you can check their status at any time by issuing the jobs command:

    > jobs

    A list of your current background programs (jobs) will be listed, for example:

    [1] + Running       sas
    [2] + Running       sas

    If you wish to kill (terminate) one of them prematurely, you can issue, for example:

    > kill  %2

    Use %1 to represent the first job (as reported by the jobs command), use %2 to represent the second job, etc.

  • If you have a SAS program running in the background and you have logged out since you launched it, the next time you login you can check on its status by issuing the following ps command:

    > ps  -fC  sas

    where -fC is a required option of the ps command and sas is the command or program about which you want information.  If the program is still running, information similar to the following will be displayed:

    UID     PID    PPID  C   STIME  TTY        TIME   CMD
    jdoe  35003       1  0   10:42      ?    00:00:00   sas
    which includes your Koti account name ("jdoe"), the start time for the program ("10:42"), the name of the command or program that is running ("sas"), and the program's process id ("35003").  If the program has already finished running, no information about it will be displayed.

    If you wish to kill (terminate) that program prematurely, you can issue the kill command as follows (for example):

    > kill  -9  35003

    where 35003 is the program's process id (as reported by the above ps command), and -9 is a required option of the kill command.

Where SAS Temporary Files Are Stored In Unix

When you run a SAS program on Koti, SAS usually needs to create one or more temporary files in order to do its work.  This is all done transparently to you.  These files are stored in the directory named ". _scratch" that is located in your home directory (note the period and underscore in the name). These files are usually automatically deleted by SAS, immediately after your SAS program finishes execution.

This article was updated: 03/21/2019