SAS on the Unix Server
- Running SAS
- Naming Conventions In SAS
- How To Create And Run A Batch SAS Program on Koti
- Submit A SAS Program To Run In The Background
- Where SAS Work Files Are Stored In Unix
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.)
- 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 "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:
- Login to Koti.
- When you receive a command prompt, type the 'sas' command, followed by the name of your SAS program file (e.g., myprogram.sas) and press Enter, for example:
- Interactive 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' (select File / Exit) in the SAS Program Window, 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';
- 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 '~/myfolder';
- The tilde character '~' represents your home directory (such as /home/jdoe).
- Yourlibname is a libref for the myfolder directory, located within your home directory.
LIBNAME Yourlibname '.' ;
- The period '.' represents your current directory.
- Yourlibname is a libref for the current directory.
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).
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.)
- For example, if you have a long-running program named "sasdemo.sas", you could issue this command:
> sas sasdemo.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:
A list of your current background programs (jobs) will be listed, for example: + Running sas sasdemo.sas
 + Running sas anotherprog.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 log in 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):UID PID PPID C STIME TTY TIME CMDThis information 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 sasdemo.sas"), and the program's process id ("35003"). If your program has already finished running, no information about it will be displayed.
jdoe 35003 1 0 10:42 ? 00:00:00 sas sasdemo.sas
psmith 29411 1 0 11:09 ? 00:00:00 sas myprog.sas
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: 04/27/2020