Section 2.7 : How to Run a SAS Command File From your PC On a PC you will probably run most, if not all, command files from the SAS display manager. When you have invoked SAS, in the Enhanced Editor you may either enter commands into a new file or open an existing file and make any necessary edits. To run the command file, refer to the LOCAL menu and apply SUBMIT. The shortcut is to click the icon that shows the rather small person "running" in the upper right corner of the screen. Important Note: if you haven't already moved the icon, the one next to it clears the screen. For safety reasons you should move it away from the Submit icon. To do so, see the first part of Section 1.5 found at: http://www.uoregon.edu/~robinh/015system.txt Before you run a file, you may want to delete all existing output, graphs, and contents of the log window. To do so, enter these commands: DM "clear output"; * clears the output window ; DM "clear log"; * clears the log window; DM "GRAPH; CANCEL;"; * deletes graphs and closes the graph window ; Be sure you have checked these windows for any contents you want to save or review before invoking them. For ease of use, they can be entered into a macro which can be invoked with a few letters, e.g. %dlo could be a four-character substitute for the longer DM "clear output"; task (See Chapter 9). You can also assign one, two, or all three of them to one of the 12 function keys as the top of your keyboard. Running a File in Batch Mode To run a command file on a PC in batch mode you will need to either go to the directory where sas.exe is stored and invoke the drive and path of the file name, or type the full drive and path name within double quotes from the command prompt line: "c:\Program Files\SAS\SAS 9.1\sas.exe" myfile.sas Batch mode is possible from the command prompt window and may be of greatest value to run big jobs in the background while you work on other tasks. When you run command files in batch that want to produce graphics, enter the -noterminal system option: sas.exe -batch -noterminal myfile.sas Run SAS from UNIX To run SAS command files in the batch mode on a unix system, first edit your command file with a text editor such as pico and then submit it by entering a command at the system prompt. This method allows you to easily store the all relevant commands in a file, reuse or modify them later, trace error messages in the corresponding log file, and then examine the output lst files. After editing the program file on unix at the system prompt enter: sas command_file_name where command_file_name is the portion of the SAS file name (all characters before the period) which contains the SAS program statements. This input file should have the extension *.sas (i.e., .sas); however, it is not necessary to use to include the extension (.sas) to run the program. With whatever system you have, when you run SAS in batch mode, two files, .log and .lst, will appear in your directory with the output of the program. If you need to turn off the X windows on unix, such as when running the PROC EXPORT or PROC IMPORT or procedures that automatically produces graphs, enter the -noterminal option: sas command_file -noterminal To learn more about SAS in batch mode on unix refer to: http://www.usc.edu/isd/doc/statistics/sas Other Ways to Submit SAS Programs on unix For programs that will take a large amount of cpu time on a UNIX system, you may want to submit these jobs to run overnight. You can insert a series of unix commands during the day to run your job at a pre-specified time. To run these jobs you should place the full file directory specification into any LIBNAME, FILENAME, INFILE, or FILE statements. This is also true for any statement that references an external text file. The at command on unix allows you to specify how to run a job at a later time. To use it go to the root directory and then enter commands similar to the ones shown here. This set of commands show how to schedule 2 jobs to be run by sas at 1:30 AM tomorrow morning: 3% at -m 0130 tomorrow at> sas ~/simul/dtstp1 at> sas ~/simul/dtstp2 at> -m indicates an email message will be sent to notify you the program ran 0130 indicates 1:30 AM -- other time conventions are available too. When you enter return (after the word tomorrow) you are give the at> prompt so go ahead and type the sas command on each line, giving the full subdirectory location of the file. ~/simul is the directory where the programs dtstp.sas is located is entered by typing Cntrl-D only. You can abort the entry of commands anytime with Cntrl-C. A control number and confirmation of the program time will be given when you exit. Always Look at the LOG File or LOG Window! A log file is always produced with each job submitted (called myfile.log on all systems) which summarizes what actually happened when you ran the program. Always check its contents - errors frequently happen, even with careful visual editing of the command file. The log file only checks for syntax errors - it does not provide information about errors in logic or appropriateness of the activity to the task at hand. Although it is not recommended for general applications, you may not want to send the usual information to a log file when a SAS job is run in a few computationally intensive situations. Simulations or large data processing jobs can rapidly use up free disk space by producing vast quantities of comment lines within a log file. You would probably like to prevent this from happening! Here are several possible solutions: The first approach produces a log file, but greatly reduced in size: * turn off notes and source code ; OPTIONS NOnotes NOsource; * turn notes and source code on ; OPTIONS NOtes source; You can redirect log contents to another disk ; FILENAME templog "C:\sas\log.txt"; PROC PRINTTO LOG=templog; Or with a shorter version: PROC PRINTTO log='log.txt'; RUN; To stop printing to the log file, enter: PROC PRINTTO LOG='null'; RUN; * be sure to use 'null' and not 'nul'; To return to printing the log information in the log window enter: PROC PRINTTO LOG=log; RUN; You can also automatically copy the log file to a back up file every time a SAS session ends. To do so add this line to the SASv9.cfg (see Section 1.5 on how to find this file): -altlog '' This command saves a copy of your program log to the named folder. Debugging SAS Programs Some of the most common errors when writing SAS command files include: 1. Failing to end a SAS statement with a semicolon. While it's not absolutely necessary, it's helpful to write a maximum of one SAS statement on each line. This practice usually makes program debugging (especially checking for the absence of semicolons) much easier. 2. Omitting one of the two quotes required to surround a string of characters. 3. Mis-spelling a SAS statement keyword, option, or variable name. Several ways to minimize errors when writing SAS programs are listed in Chapter 1, Section 9: "Minimize Errors"