6. Sample SAS Session
The following sequence of instructions will step you through a sample SAS session, including creating a data file and processing it with a command file. If you prefer to run SAS in a point and click mode, you can use Enterprise Guide. If you are working in the student computer lab, be sure to use a flash drive or floppy disk to store the data and program files.
1. Create the data file
The data to be processed should be in a file, in rectangular form, with variables as columns and the observations as rows. If you type the data in to the Viewtable Window, it must be saved as a SAS data file before executing the SAS program. Follow the instructions above for using the Viewtable Window. Alternately, you can type the data into Notepad or use some other software which will produce an ASCII text file. For this sample session, the data represents the results of a taste test on four varieties of oranges, and contains the variety name plus scores for flavor, texture and looks. Create an ASCII text file containing the following information and save it on your disk in drive A: as ORANGES.DAT.
navel 9 8 6
temple 7 7 7
valencia 8 9 9
mandarin 5 7 82. Type the program statements
Initiate a SAS session and in the Editor Window, type the following program statements. You can use the arrow keys to move the cursor around and use either the delete or the backspace key to delete text. Also, cut and paste editing is available; click on Edit and then select Cut, Copy or Paste as needed. Variable names can be up to 32 characters long, must begin with a letter or underscore and can not contain any spaces. Note that the "run;" statement is not required at the end of every Data and Procedure step, but it is recommended. If the last procedure in the job does not end with a "run” statement, that procedure will not be executed.
/* ORANGES.SAS
Program to process the ‘oranges.dat' data set. */
libname mydisk 'A:\';
data mydisk.oranges;
infile 'a:\oranges.dat';
input variety $ flavor texture looks;
total = flavor + texture + looks;
run;
proc sort ;
by descending total;
run;
proc print ;
title 'Taste Test Results for Oranges ';
run;
proc univariate;
var total;
run;
If the data has been typed in to the Viewtable Window with the appropriate variable names (column titles) and saved as a SAS data set named “oranges.sas7bdat” on the disk in drive A:\, then replace the above Data Step with the following program statements. Note that while variable names can be up to 32 characters in length, libref's (eg. mydisk) are still restricted to 8 characters maximum The three Proc steps will remain the same.
libname mydisk ‘A:\';
data mydisk.fruit;
set mydisk.oranges;
total = flavor + texture + looks;
run;
3. Save and then execute the program statements
Click File > Save. Again be sure the file is saved on your flash drive or floppy disk, and give it the file extension *.SAS. Select a filename of your choice. To execute the program, click Run > Submit, or click on the Submit tool, the picture of the person running.
4. Check the LOG window
If the program had no errors, the Output window will immediately appear. However, you should ALWAYS check the Log window before assuming that the results in the Output window are accurate and complete. If there are Warning messages, output may be generated, but it may not be complete. Bring up the Log window by clicking Window > Log, or click on the LOG button at the bottom of the screen. If there are errors they will need to be corrected and the program re-run.
5. Correcting errors
Return to the Editor window, and correct program statement errors. Save modifications by clicking FILE > SAVE, and rerun the program. For information on correcting program errors, click Help and then search the online documentation.
6. Results Window
The Results Window is like a table of contents for your SAS output. There is one entry for each procedure that produces output. Click on the plus sign in the tree diagram in the Results Window to expand the various parts of the output. Double click on a part of the output you want to see, and that part will move to the top of the Output window.
Note that the contents in the Log window and the Output window are cumulative. When you rerun a program, the additional Log or Output information is added to whatever may already be in these windows. If you want to clear a window, make that window the active window and then click Edit and Clear All. However, **** REMEMBER **** once the contents of either the Log or Output window has been deleted, it can not be recalled.
7. Print results
After the program has run successfully, you can print the contents of the Output window. Select the Output window as the active window and click File > Print. You can also print the Log or Editor windows in the same way.
To print a single section of the Output window, first select the printer you wish to use, if other than the default printer, by clicking File > Print setup. Then right mouse click on the desired section in the tree diagram in the Results window. In the menu that appears, click on Print.
If you want to print only a portion of the Log or Program Editor window, you can copy the desired text to the Clipboard and print from there. Mark the text to be printed by clicking and dragging with the mouse, and then select Edit and Copy, to copy it to the clipboard. Next select File and Print, and in the Print dialog box click on the arrow under “Contents of:" and select "Clipboard". Then click OK.
8. Copying output to MS Word
You can copy procedure results from the Output Window to an MS Word document. In the Output Window, click Edit > Select All, or mark a portion of the output text by clicking and dragging with the mouse. Click Edit > Copy. Finally, start an MS Word session and click Edit >Paste
9. Creating HTML Output
Using SAS in the Windows environment you can create HTML output in addition to the listing format. Click on Tools > Options > Preferences, and in the Preferences window, click on the Results tab. You can create just HTML output or you can create both listing and HTML output simultaneously by clicking in the appropriate boxes. The HTML output can be stored in your temporary work folder, or more permanently in a folder you specify. If you specify a folder, the files will be named “sashtml.htm”, “sashtml1.htm”, sashtml2.htm”, etc, with each procedure creating a different file. Be sure to rename these files (using Windows Explorer or MyComputer) because they will be overwritten in a future SAS session. You can view the results with your preferred browser or with the Internal Browser, which will display the HTML output in the Results Viewer. Click OK to close the Preferences window. Return to the Editor window and submit your SAS program. The Results window will now contain pointers to both the listing and the HTML output. If the HTML output was created in the temporary work folder, it can now be saved: click on File > Save As and specify a folder and file name.
10. Save the contents of the windows
*** IMPORTANT *** The system will NOT remind you about saving the contents of the Log and Output windows when you exit from the SAS system, so you must remember to do this if you want this information saved. (Note – it will remind you, however, about saving the contents of the Editor window.) Click in the window to be saved, making it the active window, and from the main menu click File > Save . Choose file names that will help remind you of the file contents, and use file extensions as follows: .SAS for program files, .LST for Output window files, and .LOG for Log window contents.
11. Exit SAS
To exit from the system, click File > Exit. You will be asked if you really want to terminate your SAS session. Respond “Cancel” to return to the SAS system and continue working, or “OK” to complete the exit process.

