Using SAS Fall 1992 SAS Primer Using the SAS System This section describes how to use the SAS Display Manager to analyze your data. The display manager provides an editor for creating your SAS program and data, lists the SAS log created when you run the program, and displays the statistical output from your program. You can find additional information about the Display Manager from the "SAS Language Guide for Personal Computers". Getting in and out of SAS After you log into your account you will see the system prompt. To start SAS, type the command "sas" and press the RETURN key. If you are using the UNIX operating system this must be entered in lowercase. If you get an error message, check with your course instructor or system manager. It takes SAS a few moments to get started; you will see many messages flash by so be patient. To end your SAS session type the command bye after the prompt "Command===> " at the top of any SAS window and press the RETURN key. SAS does not differentiate between upper and lower case characters. Therefore, you may use upper or lower case for all the commands you find in this manual. However, when saving a file or including an existing file into the work area of the SAS Display Manager the name of the file is "case sensitive". This means that if you tell SAS to access a file with the name EXAMP and the file is stored as examp on system disk, a message will appear saying the requested file does not exist. The main SAS windows SAS Display manager creates several windows for your use. Each of these windows is a work area used for a specific task. SAS has three primary windows you will use regularly: the Program Editor window where you input, edit, and save SAS programs and submit SAS statements the Log window where you will browse through messages about the program statements you submitted to the SAS System. the Output window where you will examine the statistical results and graphics created from your statements submitted to the SAS system. At the top of each window you will find the command line prompt: Command ===> The line containing this prompt is called the command line. The (HOME) or (FIND) key will place your cursor after this prompt. You will enter commands after this prompt to move from one window to the next or to position text within the window. The following commands can be entered after the "Command===> " prompt in any of the windows. Type this COMMAND in any window =============================== ====================================== Command===> pgm activate program editor window Command===> log activate log window Command===> out activate output window Command===> print print the contents of the active window Command===> clear clear the contents of the active window Command===> top bring the top of the active window into view Command===> bottom bring the bottom of the active window into view Command===> up n scroll the window up n lines Command===> down n scroll the window down n lines Command===> right bring the right side of the active window into view. This is useful if you type past the 80 characters normally visible or if you set your output linesize to 132 which is typical of mainframe output. Command===> left bring the left side of the active window into view. Command===> nnnnn bring the line with line number nnnnn to the top of the window Command===> ? recall the previous command executed. It will continuously cycle through the last several commands that were executed. Command===> zoom cause the display of the active window to take over the entire screen. Executing zoom again will reverse this. Command===> file 'filename' Save the contents of the active window in a file with the name filename. Command===> bye exit from the SAS display manager session. The following commands can be used only in the Program Editor Window: Type COMMAND in Program window YOU CAN =============================== ====================================== Command===> recall Recall the most recently submitted lines of SAS statements Command===> inc 'filename ' Reads a previously stored file into the program area. Command===> help Invokes the SAS help facility. The Program Editor window Use the program editor window to create or include an existing SAS program, modify the SAS statements, and submit the program for execution. Here the term "include" refers to reading in a previously stored SAS program. After entering the SAS display manager, you will usually see only the program editor window. The area of the window containing the line numbers is the programming area where you can create and modify your SAS statements. When you first start SAS, you are in typeover mode. This means if you type characters in the middle of a word, the characters will type over the word. To switch to insert mode, so characters are inserted into the word, press the (Insert) key (if you are using a vt100, vt200, or vt300 terminal) or the (Ins) key.(if you are using Sun workstation). If you are on a terminal which does not have an insert key, try the key combination Control-N . This same key will switch back and forth between insert mode and typeover mode. You know you are in insert mode if there is an I in the bottom right corner of the screen. *PROGRAM EDITOR************************************************* Command ===> THIS IS THE COMMAND LINE PROMPT * *00001 *00002 *00003 *00004 *00005 *00006 *00007 *00008 *00009 *00010 *00011 *00012 *00013 *00014 ENTER COMMANDS TO DELETE, ADD, COPY OR MOVE LINES OF TEXT ON *00015 TOP OF THE LINE NUMBERS *00016 *00017 *00018 *00019 *00020 ZOOM I I INDICATES INSERT MODE FIGURE 1. Program window in ZOOM mode. To see the log window, output window and program window at the same time, type ZOOM on the command line. ZOOM toggles between the two modes. Creating a file Move the cursor into the programming area of the Program window. The cursor will need to be sitting one space to the right of any line number. If your cursor is at the command line prompt, pressing RETURN will move the cursor to the correct position. Type in your program. Include an existing file If you want to use an existing SAS program use the include command: Command===> include 'filename ' Save a file you just created or modified. To save a file you have just created or modified use the file command: Command===> file ' filename ' where filename complies with the rules for naming files on your system. If the file exists SAS will ask you to verify that you really want to overwrite the contents of the original file. If you do not use the file command to save your program, it will not be available to you the next time you sign onto the system. Change a string of characters To change one or more occurrences of a string of characters use the change command: Command===> change 'oldstring ' 'newstring' [next|first|last|prev|all] [word|suffix|prefix] The keywords enclosed in the double brackets are optional and are used to control the direction in the window SAS searches for the oldstring and the context the oldstring must be in. By default SAS searches for the next occurrence of oldstring. Which particular occurrence of oldstring is found depends upon the current cursor location. The other choices are previous, first, last, and all. By default, oldstring is changed to newstring regardless of context. You can also specify one of the options prefix , suffix, or word to specify the context the oldstring must be in for the change to occur. In the change command, as in the find command, a word is one or more symbols preceded and followed by any symbol other than an uppercase letter, a lowercase letter, a digit, or an underscore. For example: Command===> change 'day' 'night' will change daybreak into nightbreak and friday into frinight. With the "prefix" option only daybreak is changed and with "suffix" only friday is changed. If the oldstring or newstring that you want to use contains special characters or embedded blanks enclose the oldstring or newstring with apostrophes. Single word strings can be specified without apostrophes. Find a string of characters To find a specific string of characters, use the find command: Command===> find 'string ' [next|first|last|prev|all] [word|suffix|prefix] The find command will position the cursor at the specified string of characters. The optional keywords enclosed in double brackets function the same as they do in the change command. For example, if you have a message saying you misspelled PROC as PROG use the command Command===> find 'PROG' to locate the word in your program or use the change command to change it. Insert lines of text To insert lines of text move the cursor until it is in the line number field. Type one of the following commands to insert one or more blank lines: Type this in the line number field, then press the RETURN key I[n ] Insert one or more (n) blank lines. To insert more than one line, follow I with some number n and press the RETURN key. IA[n ] Insert one or more (n ) lines after the line on which you enter the IA (insert after command). By default only one blank line is entered. IB[n ] Insert one or more (n ) lines before the line on which you enter the IB (insert before) command. By default only one line is inserted@ Delete lines of text You can delete an individual line or a group of lines by entering the following commands in the line number field of the line or group of lines you want deleted: Type this in the line number field, then press the RETURN key. D[n ] Delete one or more (n ) lines. By default, one line is deleted. To delete more than one line, type the number of lines you want deleted (n ) after the D. DD Delete the group of lines selected by typing DD in the line number of the first and last line of the group. Copy or Move lines of text Lines can be copied or moved by first designating the lines of text with commands entered in the line number field. Then type an appropriate destination command to replace the line number of the line coming before or after the new location. Choose from the following commands: Type this in the line number field to select one or more lines to be moved or copied M[n ] Moves one or mores (n ) lines to another location in the file, indicated by a destination line number command. MM Moves a group of lines selected by typing MM over the line numbers of both the first and last line in the group. The group will be moved to the location indicated by a destination line number command.@ C[n ] Copies one or more (n) lines to another location in the file, indicated by a destination line number command. CC Copies a group of lines selected by typing CC over the line numbers of both the first and last line in the group. The group will be moved to the location indicated by a destination line number command.@ Type this in the line number field and press the RETURN key to choose a destination for a selection of lines (Choose the Destination with these Commands) A[n ] Moves or copies the selection after this line and duplicates the selection n times. The default is to duplicate the selection once. B[n ] Moves or copies the selection before this line and duplicates the selection n times. The default is to duplicate the selection once. Executing your program You can use the submit command to have SAS process all of the statements displayed in the program window by using the following command: Command===> submit SAS will put messages about program execution in the log window and statistical results in the output window. Unfortunately, SAS defaults to append this information to the previous contents of the log or output window. To clear these windows before using the submit command in the program window, type the following sequence of commands: Command===> log Command===> clear Command===> output Command===> clear If you are using the SICL computer system at NCSU, the following command has been set up to clear the contents of the log and program window and then submit your SAS statements for processing: Control-E It does not matter where your cursor is setting when you type Control-E. If the computer system you are using does not have this key definition, you can use the Function Key Definition Screen to define a key to this or any other sequence of commands you enter on the command line of the active window. See the SAS manuals at your computer center for more information. After you have examined the log and output windows, you may want to save or modify the SAS statements just processed. When you return to the program window by using the command Command===> pgm the window will be empty. You will need to recall the last set of statements processed using the command: Command===> recall After you have used the recall command to retrieve the most recently submitted group of program statements, you can enter it again to recall the next most recent group. The lines will be inserted in front of any other nonblank lines already displayed. The Log Window To activate the log window use the following command: Command===> log The log window contains the program statements you submitted along with notes and error messages. Use the file command to save the contents of the log window. Enter the top, bottom, up n, or down n, commands after the Command===> prompt of the output window to page through the output. Notes include information about any set of data you have read or created (number of variables, number of observations and number of missing values) and length of time each SAS procedure used. SAS also will warn you about any assumptions it makes about the spelling of SAS procedure names and options and keywords and any computational problems that arise, such as trying to invert a singular matrix. Syntax errors that prevent your program from producing the desired output will produce an error message in the log file. Go back to the program window, recall your program, fix the error and execute you program again. The Output Window The results from your SAS program appear in the output window. Enter the top, bottom, up n, or down n commands after the Command===> prompt of the output window to page through the output. You can again use the file command to save the contents of the output window.