Guide to Using SAS for Windows
Note: Return to reference manual view.
1. Introduction
SAS, Statistical Analysis System, is a very large, comprehensive software system with tools for data access, management, analysis, and presentation. The Windows version of SAS contains the following 20 modules: BASE SAS, ACCESS, AF, ASSIST, CONNECT, EIS, ETS, FSP, GIS, GRAPH, IML, INSIGHT, LAB, OR, QC, SAS/SECURE, SHARE, SPECTRAVIEW, STAT and TUTOR. In addition, we have Enterprise Miner, Enterprise Reporter, Enterprise Guide (point and click access to the SAS system), Warehouse Administrator, SAS/Intrnet and JMP. This document describes using Base SAS to enter data and execute a statistical procedure. Refer to other documentation as needed.
The latest SAS software release, version 9.1.3, contains many new features and improvements. To get an overview of what's new, point your browser to:
http://support.sas.com/software/91x/toc.htm2. Overview
The Windows version of SAS provides five main windows: Explorer, Results, Program Editor, Log and Output window. You start the system (in the student computer labs) by clicking on Start > All Programs > Statistical Software > SAS > SAS 9.1 (English). When you initiate a SAS session, three windows are visible, the Explorer, Log, and Enhanced Editor windows. The Results window is behind the Explorer window, and the Output window is behind the Log and Editor windows. The Program Editor window can be created in addition to the Enhanced Editor window by clicking on View and then Program Editor.
The Explorer Window enables you to view and manage your SAS files. You can create new libraries and new SAS files, as well as move, copy and delete files. You can also choose to show a tree diagram of your files: click in the Explorer window, and then click View > Show Tree.
In the Enhanced Editor Window , you enter, edit and submit SAS programs. This window provides some improved editing features compared to the Program Editor Window. Improvements include: color coding and syntax checking of SAS program statements, expandable and collapsible sections, and bookmarking of different sections. You can open multiple instances of the Enhanced Editor simultaneously. To execute a program in the Enhanced Editor Window, click on Run and Submit, or in the tool bar, click the icon showing “a person running”.
The Log Window displays messages about your SAS session. After running a SAS program, the Log window contains a copy of your submitted program and any notes, errors, or warnings associated with the submitted code.
****** IMPORTANT****** ALWAYS check the Log window for important notes or warnings before assuming the output is correct.

The Output Window contains the results produced by the SAS program statements. This window automatically moves to the front of your display when output is created.
The Results Window helps you navigate and manage SAS output. It contains a tree diagram of your output, and enables you to view, save and print individual items. The Results Window also moves to the front of the display when output is created.
These five windows are the primary windows in the SAS Windows environment. Only one of them can be the current active window. The bar at the top of one of the windows will be darkened to indicate which window is the active window. To select a different window as the active window, simply click in the desired window. Alternately, you can click on “Window” in the main menu and then select the desired window from the drop down list. Buttons for the individual windows are also listed along the bottom of the screen, and you can click on any one to make it the active window.
In addition to the five main windows, the SAS Windows environment creates other windows as they are needed. Also, there are several features available to assist in using the system: a menu bar with drop down lists, a tool bar, command bar, status line and window bar.
The Menu bar is at the top of the screen. When the Enhanced Editor is the active window, the menu selections are: File , Edit, View, Tools, Run, Solutions, Window and Help. Clicking on one of these menu items produces a list of available actions. As you switch between application windows, the menu bar changes to reflect the actions that are appropriate for each window. For example, Run is not available when the Log window is the active window. Y ou can also right click within an application window to see the menu items available for that application window.
The Command bar is in the upper left hand corner, and it provides a place to type SAS commands. Most of the commands that can be typed in the command bar are also available in the pull-down menus or the tool bar.
The Tool bar provides quick access to the commands you perform most often. It is completely configurable. Tools that are not appropriate for the current active window are grayed out.
The Status Line is at the bottom of the screen and contains a message area identifying the current folder for the SAS System. The message area displays help text for menus and tools, and messages specific to the SAS application windows. The current folder (sub-directory) is the current working directory, and this can be changed during your SAS session.3. Help
The
SAS system provides comprehensive online support at several different
levels. All of the reference manuals are now available on line in HTML
and PDF format. Point your browser to:
http://support.sas.com/documentation/onlinedoc/sas9doc.html
Also, within your SAS session you can get help for all SAS products or you can get task-specific help for one window at a time. Click Help in the main menu to produce a drop down menu containing the following items: “Using this Window”, “SAS Help and Documentation”, “Getting Started with SAS Software”, “Learning SAS Programming”, “SAS on the Web”, and “About SAS 9”.
Getting Started with SAS Softwareinitiates the SAS tutorial.
SAS on the Webgives you a direct link to SAS Institute's Home Page, to the Institute's Frequently Asked Questions, and to SAS technical support.
SAS Help and Documentation opens the “Welcome to SAS 9.1.3 Help and Documentation” screen from which you can make menu selections to read about the entire SAS system or select specific topics of interest. The left hand panel in this Help window allows you to select Contents, Index, Search or Favorites. Under Contents, you can select from: “What's New”, “Learning to use SAS”, “Using SAS Software in your Operating Environment”, “SAS Products”, or “SAS User Support Services”. With the Index tab you can enter a specific word or SAS command and obtain help on that one command.4. User Guides and Documentation
SAS
documentation is available in three formats: HTML, PDF, and hard copy.
SAS OnlineDoc is a complete reference for the SAS system, covering Base
SAS as well as all the SAS modules, and it can be accessed by pointing
your web browser to:
http://support.sas.com/documentation/onlinedoc/sas9doc.html
This
web site will give you access to both HTML and PDF versions of the
documentation. For information about the printed documentation
available, point your browser to:
http://www.sas.com/apps/pubscat/welcome.jsp
For the new user, the following book provides an easy-to-read introduction to the most commonly used features of SAS software. The book covers getting started with SAS software, getting data into the SAS system, working with the data, and summarizing the data with reports, tables and some basic statistical procedures.
“The Little SAS Book: A Primer, Third edition”, ISBN: 1-59047-333-7. $45.95
All hard copy documentation for the SAS system can be ordered from:
SAS Institute Inc. phone: (800) 727-3228 fax: (919) 531-9439
Cary , NC 27513-2414 email: sasbook@sas.comor from the web: http://www.sas.com/apps/pubscat/welcome.jsp
5. Features and Utilities
Explorer Window
The Explorer Window gives you easy access to SAS files and libraries. You can create new Libraries, Files or File Shortcuts. If you plan to access an existing SAS data set, or create a new one, it is important to define a “libref” for the folder or subdirectory that contains, or will contain the SAS data set. The term “libref” is short for SAS library reference, and it can be thought of as a nickname or arrow pointing to a particular folder or subdirectory on your system. To create a libref, make sure the Explorer Window is the active window and then click on the New Library icon in the toolbar, or click on File > New > Library. In the New Library window, enter a name for the libref (8 characters maximum, must begin with a letter, and can not contain spaces) and an Engine (use Default or V9). “Engine” simply refers to the access method, or set of internal instructions SAS will use in reading or writing files in the specified folder. Finally, in the Path window, specify the subdirectory or folder where you want to save the new SAS data set and click OK.
Viewtable Window
The Viewtable window can be used to create, view, or edit a SAS data set. Two views are possible, "Table View", consisting of rows and columns, and "Form View", which displays only one observation at a time. In Form View you can use the default data layout or create a customized design to meet special needs.
To initiate Viewtable to create a new file, click Tools > Table Editor. The initial Viewtable window displays rows, which represent observations and are labeled with numbers, and columns, which represent variables and are labeled with letters. You can click on the letter at the top of each column to enter a title, and you can type data directly into the grid, but it is usually better to define the column or variable attributes before entering data. Click on Data and Column Attributes. If necessary, move the Column Attribute window so that the row of column letters is visible, and click on the first column letter. In the Column Attribute window enter a name for the column, a label, format and data type. Variable or column names can be up to 32 characters long, must begin with a letter and can contain letters, digits or the underscore, but they can not contain any spaces. Click on each column that will be needed for the data set, enter that column's name and attributes, and when complete, close the Column Attribute window and begin entering data. When entering data press the tab key to move across each row, or press the Enter key followed by an arrow key (either across or down) to move the cursor to the next data cell. To save the data as a SAS system data file, click File > Save or Save As. In the “Save As” window, click on the library (subdirectory) where the file is to be saved and type in a “Member Name”, ie. filename for the saved data set. The filename should not contain any spaces. The filename extension will be “.sas7bdat”.
You can also browse or edit an existing SAS data set in the Viewtable window. Click on the Explorer window to make it the active window, and browse to the libref containing the desired file. Double click on the filename to open the file in the Viewtable window. Alternately, you can click on Tools > Table Editor to open the Viewtable window first, and then click on File > Open. The left hand side of the Open dialog box will list the libraries or librefs currently identified in your SAS session. Select the library and SAS data set that you wish to view. The file is opened in Browse mode, but you can switch to Edit mode by clicking on Edit > Edit Mode. Be sure to specify Row Level Edit Access or Table Level Edit Access. You can edit individual cells, add, delete or copy rows, or sort the data. You can not add a new column. To add a row or rows, click on Edit > Add Row or click on the Add Row icon, and add the data for the new row. To continue adding new rows of data, click the Add Row icon again. When all the new data has been entered, click on the Commit New Row icon. NOTE: it is important to remember that when you enter new data it is saved immediately and automatically in the file. If you change your mind on any of the additional data items, you must go back and delete the item or items.
Converting SAS Version 8 Data Sets and Catalog files to Version 9
SAS version 8 data files (*.sas7bdat file extension) can be read and updated by SAS 9.1.3 directly, without doing any conversion. If you simply read your version 8 data set into a SAS 9.1.3 session and save it, it will be saved as a version 9 file. However, SAS version 8 catalog files (*.sas7bcat file extension) require the use of Proc Migrate to convert them to version 9. Use a program similar to the following:
/* SAS program to convert version 8 catalog files to version 9 */
libname source v8 ‘folder location of v8 catalogs, ie. c:\v8catalogs';
libname target v9 ‘folder location of v9 files, ie. c:\v9catalogs';
proc migrate
in=source out=target;
run;
Import Wizard
The SAS Import Wizard
can be used to read data sets in a variety of formats: Microsoft
Access, Excel, dBase, Lotus, comma separated value (*.csv), other
delimited files, or a file in a user defined format. Before using the
Import Wizard, you should set up a libref for the folder where you want
to save the new SAS file. If you skip this step then the new SAS file
can be saved in the default SASUSER folder:
C:\Documents and Settings\ username \My Documents\My SAS Files\9.1
Refer to the section above, Explorer Window, for details on creating a libref.
To import a Microsoft Excel file: in the main menu, click File and Import Data to open the Import Wizard. There are two initial choices, "Standard data source" or "User defined file format". Click the “Standard data source” box, and in the “Select a data source from the list below” window, be sure that “Microsoft Excel 97, 2000, or 2002 Workbook” is selected. Click Next and in the “Connect to MS Excel” window, browse to the location of the Excel file and click OK. The Options button allows you to specify a specific Worksheet/Range, to state whether or not the first row contains variable names, and to specify how to handle date variables. Note: only one worksheet can be imported at a time. Next you will need to specify a destination for the SAS file, a libref (Library name) and a data set name (Member name). After entering this information, you can lick Finish to complete the import process or Next to get the option of saving the Proc Import statements. After clicking on Finish, the Log window will contain a message stating that the SAS data set has been successfully created, or error messages if the process was not successful. Once the SAS file has been created you can view it in a Viewtable window or refer to it in a Data or Proc step.
A Microsoft Access file can also be imported and saved as a SAS data set. The procedure is essentially the same as that used for an Excel file, except that in the “Select import type” window, specify “Microsoft Access 2000 or 2002 Database”.
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.
