Chapter 1.3: RUNNING SAS ON MICROSOFT WINDOWS 1. How to Start SAS for Windows a) With the mouse, point to the START menu, then ALL PROGRAMS, and the “The SAS System” followed by “The SAS System for Windows V8”. A single click will load SAS. b) Make a shortcut. You can set up an icon on your desktop to run SAS if one does not currently exist. To do this, go to “My Computer” and Follow the path to location of the sas.exe file. Highlight this name with your mouse and then right-click and press ‘Create Shortcut’. [Be very careful not to press ‘Delete’ or some other choice on this menu.] c) Appendix A of this document describes three of the standards windows you will see in text form. You can maximize any SAS window by clicking on the square in the upper right corner of the respective window. You can also close it by clicking the X. 2. Practice session using the menus a) With the mouse point to the File menu in the upper left hand corner. Click the left button to pull down the menu. b) When the menu appears, read the various choices it offers. c) Use the mouse to choose other menus along the top and observe what choices they offer. Each menu appears until you click another choice or somewhere else on the screen. d) Many menu choices invoke another window, for example ‘Save As’. When you click a choice, a dialog box will appear prompting you for more information, such the pathname, your choice of file name, and the type of a file to save. e) Throughout these instructions, the process of using the mouse to point to a menu such as the File menu, clicking the left mouse button to pull down a menu and then using the mouse to choose a menu selection such as Exit, will be abbreviated, “File -> Exit”. 3. Activate the various windows a) Use the mouse to click anywhere in the Log window. Its title bar will recede indicating that it is now the “Active” or “Activated” window. This means that any option you select from the menus will affect this window. Menu items or options relevant for other windows will not be available (such as ‘Run’ for the Editor window). b) Select the Enhanced Editor window. See how its title bar now becomes recessed. If the Enhanced Editor does not appear by default when you start up SAS, you can tell SAS to do so by going to the Tools -> Options -> Preferences -> Edit window and click the box for Enhanced Editor (you can read more about this editor in section 15, system set-up). c) Activate the contents of the output window by clicking in the portion of the window you can see, choosing View -> Output, or click the tab at the bottom of the screen. Depending on how large you set it, the size may cover most if not all of the other windows. The active window will always cover any other windows that overlap its window space. d) If you don’t see the Enhanced Editor as a choice of a window, you can create a new one by choosing View -> Enhanced Editor. A blank one will appear ready to insert an existing program or to write a new one. In fact, you can select several editing windows at once, each containing a separate program. The choice of the basic Program Editor is also available; however, the Enhanced Editor offers some additional features that you will probably find most useful when writing SAS programs. e) Activate the Log window by choosing View -> Log. It will appear as the active window. f) Activate the output window by choosing View -> Output. Return to the Enhanced Editor by clicking on the editor tab. Note how the Log and the Enhanced Editor windows are deactivated. This is a convenient short cut to use when you're done looking at output. 4. Enter a program and submit it for execution. For most SAS procedures and to read data from external files into datasets require that the user to write or edit a series of SAS statements called a program. In the Windows environment, programs are written or opened and edited in the ENHANCED EDITOR Window (you will likely want it to be the default), and then submitted for processing from that window. The LOG window displays the executed code and messages, and the OUTPUT window displays the results. The SAS ENHANCED EDITOR is a reasonably flexible text editor, with cut, copy and paste, as well as find and replace commands. This editor which first appeared in version 8 applies color-coding and dividing lines to help you keep track of SAS syntax features and to more efficiently detect errors. The Enhanced Editor helps to reduce the number of programming errors, usually a simple typographical mistake – such as not entering quotes correctly or omitting the semi-colon. These errors can be very time-consuming to find when proofing and testing programs with other editors. New users should especially select the Enhanced Program Editor as their default. a) Use the mouse to move the cursor to the top left corner of the Enhanced Editor window. A small left-hand margin exists that does not allow you to type commands. b) Enter the first line of your program and press the Enter key. The use of the Enter key makes sure that the cursor is positioned properly on the next line. Note that Example Program 1 shows the use of a permanent SAS data set already in place in a specified directory. When you work on your own computer, you can create it by following the directions for creating a permanent SAS data set. Example program 1 LIBNAME dat 'c:\data\sas'; PROC PRINT DATA=dat.sales; VAR salesrep sales; RUN; c) Continue entering each line of your program. When you reach the end of a step conclude it with a RUN; statement. d) Run the program by choosing Run -> Submit or clicking on the little human figure that appears to be ‘running’. e) The program will execute and you’ll see the results of the program status appear in the log window. If there are no errors, the data will be written to the Output window, and may automatically become the active window, covering the other windows. f) If you have several DATA and PROC steps in a program and only desire to run one or a small number of adjacent steps, highlight that portion with your mouse and then press the ‘submit’ figure. (Be sure that a RUN; statement is at the end of the submitted block.) 5. Read messages in the LOG window. a) If the LOG window is not visible, activate it by choosing View -> LOG which brings it to the active status. You can also click on the tab on the lower portion of the screen. b) Adjust the size of this window with your mouse or maximize it by clicking on the open square in the upper right corner of the Log window. You can save these settings by typing WSAVE in the command bar (upper left hand corner) and press Enter. c) Use the Page Up and Page Down keys or the slider bar on the right hand side of the screen to scroll through the messages to read them. d) Before leaving the Log window, you may want to erase the contents in the window to avoid confusion with future submissions. SAS will append further results to the LOG and OUTPUT windows with further submissions. To erase the contents of this window, first make sure it is ‘active’ and then choose Edit -> Clear All. 6. If you have output from a submitted program, look through it. The same instructions found in step 6 apply to this window also. 7. If you have errors, correct them in the Enhanced Editor window and submit the program again. a) Activate the Enhanced Editor by choosing View -> Enhanced Editor. b) If your code has disappeared when the Enhanced Editor window is active, choose Run -> Recall Last Submit to retrieve it. SAS is usually easiest to work with when the option to remove program code in the Editor window when you return to it is off. If you find your program code is not there, go to Tools -> Options -> Preferences -> Enhanced Editor -> General to find the entry that says ‘Clear text on submit’. If this box is checked, click it once to remove it. c) Correct any errors in the program and then choose Run -> Submit to process the program statements again. 8. Print the contents of any window a) Review the Page Setup and Print Setup from the File menu. Make any desired changes including margins and font size here for the printed output. b) Activate the window with the contents you want to print. c) Before you send the results to a printer, view them with the Print Preview window. d) If you want to print what exists in the active window choose Print. e) A dialog box will appear indicating the default printer choices. If you choose OK, it will print immediately to that device. 9. You can save the contents of any window. a) Activate any window and choose File -> Save As. b) A dialog box will appear prompting you to fill in a filename. Fill in a filename that specifies the drive and path name you will remember as to the location of where it is stored such as c:\sas\prog1.sas. Otherwise it will write to a default location which may be difficult to find in the future. c) Save the contents of a program file before you submit them! If you do not save them first and return to an empty Enhanced Editor window after you submitted them, you must first recall the program using Run -> ‘Recall Last Submit’ before it can be saved. 10. Open your saved program back into the Enhanced Editor window. a) Activate the program editor window, and choose File -> Open-> Read file. b) A dialog box will appear prompting you to fill in a filename, or you can move through the subdirectories until you locate where you last saved it. 12. When you are finished, exit SAS by choosing File -> Exit. When the dialog box prompts you, choose OK. See the SAS Companion for the Microsoft Windows Environment as well as Microsoft Windows User's Guide for more details. Appendix A: The SAS Display Manager System (DMS) |===========================SAS=========================| | File Edit View Tools (Run) Solutions Window Help | | | | -------------------OUTPUT---------------------| | | | | | | | | | | | | | | |-------------------LOG-----------------------| | | | | | | | | | | | | | | |--------------PROGRAM EDITOR-----------------| | | | | | | | DATA PrePost; | | | | INPUT subject $ 1-8 group 12 | | | | pre 14-15 post 17-18; | | | | Gain=Post-Pre; | | | |---------------------------------------------| | | | |=======================================================| The Enhanced or Program Editor window is used to enter and edit SAS programs. When this is the Active window the Menu includes one additional choice, 'Run'. Line numbers (1,2,3,4, etc.) can be inserted on the far left side of the Editor window, depending on whether the option has been turned on. They are of greatest use when your program is relatively long. To see line numbers as you enter statements: 1. First, select the Editor window. 2. In the command box at the top left of the SAS session, type NUMS and press enter. 3. Notice that the line numbers are visible. 4. Type anything on line 1 and press enter. The number 2 appears on the second line. Sequential numbers appear as you continue to press enter. 5. To turn off the numbering, return to the command box, type NUMS, and press enter. The Log Window contains messages summarizing the progress and error messages of your program. It is a tool for diagnosing problems with SAS programs. It is a good idea to check the Log Window after each submission of a SAS program in order to check for programming errors or warning messages. The Log Window also contains important summary information such as the number of observations and variables created. Comments of this kind always appear in blue. Error messages, on the other hand, appear in red and usually indicate that some portion of the program failed to work properly. It will usually tell you want type of code it was expecting that it didn’t find. The Output Window contains the printed output from PROC steps submitted from the editor. The Output Window only allows you to view, print, or save the information it displays. If you want to edit SAS output, you will have to either cut and paste or save the contents of the Output Window as a text file. You can then use Microsoft Word or another text editor to make changes or include additional information. Knowledge of SAS syntax, including how to use ODS, will allow you to alter the standard output provided by the numerous statistical procedures in SAS. Depending on the default window positions, this window is usually covered by the other two, and only appears when output is generated. The outermost window appears only in Windows versions of SAS. It's called the Application Work Space (AWS).