Koti is a central Unix server available for researchers at VCU.
The current release of SAS available on Koti is SAS 9.4 TS1M6.
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.)
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 "myprogram.sas") that is stored on Koti. While the program executes, you usually 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 based on the program file name (eg., "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:
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 SAS within the SAS program editor window (select File / Exit), all the other SAS windows will also close.
Filename Extensions in SAS:
|SAS dataset file:||filename.sas7bdat|
|SAS program file:||filename.sas|
|SAS listing (output) file:||filename.lst|
|SAS log file:||filename.log|
Conventions for Libname Statements within SAS:
LIBNAME Yourlibname '/home/jdoe/myfolder';
LIBNAME Yourlibname '~/myfolder';
LIBNAME Yourlibname '.' ;
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. (Note that issuing just 'cd' by itself will return you to your home 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 "demo.sas" (although not required, traditionally SAS program filenames end with the ".sas" extension). 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 demo.sas|
|7.||Use the 'sas' command to submit your SAS program to run in batch mode. SAS will create a log file named "demo.log" and, if any output is produced, a listing file named "demo.lst". When the program finishes, you will receive another command prompt. |
Note: If the batch SAS program you submit 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 (see the next section below).
|> sas demo.sas|
|8.||Use the 'ls' command to list the files in your current working directory that begin with 'demo' (the '*' is a wildcard character that matches any characters). You should see the 'demo.sas' and 'demo.log' files listed, and the 'demo.lst' file if your program 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 demo*|
> ls -l demo*
> 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:
|> less demo.log|
> less demo.lst
|10.||Copy or move (rename) your 'demo.lst' file. You may want to do this before re-running your 'demo.sas' program (which would overwrite an existing 'demo.lst' file). If the new filename contains spaces, it must be enclosed in single or double quotes.|
> cp demo.lst
> mv demo.lst 'file 2.lst'
|11.||Remove (delete) a file. If desired, you may specify multiple filenames, separated by spaces, to be removed.||> rm demo.lst|
If a batch SAS program runs 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, so long as the program will not prompt you to enter input from the keyboard). The ">" symbol displayed below represents the Unix command prompt (which will likely be different in your Koti account).
> sas demo.sas &
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:
A list of your current background programs (jobs) will be listed, for example:
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, when you log in again 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. Information similar to the following will be displayed about all SAS programs that are running on Koti, including yours (if it is still running):
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.
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: 09/10/2020