1.5 - SAS Windowing Environment

1.5 - SAS Windowing Environment

Okay, so you want to write and run a SAS program in the SAS System. How do you go about doing that? The first thing you need to do is to open your SAS software by selecting it in your programs list, or by double-clicking on the icon on your desktop, which might look something like this:

When your SAS software opens, you should immediately see something like this (that is, without the red labels, which have been added here merely for explanatory reasons):

ExplorerWindowResultsWindowOutputWindowEditor WindowLog Window“Execute the program”

See if you can identify on your screen the following five windows: the Editor Window, the Log Window, the Output Window, the Explorer Window, and the Results Window. You may have to click on the appropriate tabs along the bottom in order to activate each of the five windows. Note that a window is activated when its top blue bar appears brighter, and the window is deactivated when its top blue bar appears dimmer.

Editor Window. The Editor Window is where you type in your SAS programs. It allows you to perform standard editing tasks, such as entering, editing, and submitting programs. In the Editor window, you can also open previously saved SAS programs, as well as save new SAS programs. After you have typed in your SAS program, and are satisfied that it meets all of the syntax requirements discussed above, you can "run" (or "execute") your program by clicking on the "running man" icon . For Windows operating systems, the default editor is called the Enhanced Editor, because it gives you a nudge — through the use of differently colored text — if your program contains a syntax error. The Enhanced Editor also allows you to collapse and expand the various steps in your program.

Log Window. The Log Window displays messages about your SAS session and any programs that you submit. You should always plan on checking this window after running a program. Even though your program may appear to have run correctly, critical errors may still have occurred when reading or manipulating the data. SAS uses the following color-coded system to assist you in reading the log:

  • the DATA and PROC steps that appear in your program are printed in black
  • notes that SAS wants to report to you are printed in blue
  • warnings that SAS wants to draw to your attention are printed in green
  • and errors that cause SAS to abort running your program are printed in red

Output Window. The Output Window is where the printable results from your program appear. It is positioned behind the Log and Editor Windows until there is output to display when it automatically opens or moves to the front of your display. Examples of output that your programs might create include data listings, table summaries, charts, and character-based plots and graphs. If you review the Output Window after running a program and some output that you expected is missing, then double-check the Log Window to see if you had any programming errors that prevented SAS from executing your commands. Note, though, that not all SAS programs create output in the Output Window. If you create HTML output, for example, it can be viewed in the internal SAS browser called the Results Viewer Window. And, if you create a graph, it will appear in a separate Graph Window.

Note that if your program is creating output in the Results Viewer Window, by default, you will want to turn this feature off. Currently, SAS 9.1 and 9.2 default to the Output Window, while SAS 9.3 and 9.4 default to the Results Viewer Window. Make this change under preferences (found in the tools menu, under options). In the Preferences Window, select the Results Tab. You will want to uncheck Create HTML and, instead, select Create Listing. This is important because when SAS produces HTML it takes control of how the output looks out of your hands. One of the goals of the course is to be able to control the way your output is presented and if SAS is creating HTML results, you will not be able to do this.

Explorer Window. The Explorer Window allows you to easily view and manage your SAS files, which are stored in SAS data libraries. We'll learn more about data libraries later. For now, it suffices to know that a library name is just a nickname for the actual location — that is, a folder on your computer — of your SAS files. The Explorer Window can be used to create new SAS libraries and files, to open SAS files, and to move, copy, and delete SAS files.

Results Window. (Note that the Results Window is not the same as the Results Viewer Window described previously.) The Results Window serves much like a table of contents for your Output Window. That is, it itemizes each section of your Output Window in outline form so you can easily jump from one piece of output to another. The Results Window is empty until you submit a SAS program that creates output. Then, it moves to the front of your display.

Example 1-1

So now you've seen a basic SAS program as well as have been introduced to how to run a program in the SAS System. Let's try it out!

The following SAS program illustrates the simplest example of column input.

Copy the code below:


/********************
 This program reads in a set of grades for six
 students, and prints out their student numbers 
 and genders.
 *****************/
 OPTIONS NODATE LS=78; 
 TITLE "Example: getting started with SAS"; 
 DATA grade;
   	InPuT subject gender $
		exam1 exam2 hwgrade $; 
   DATALINES; 
   10 M 80 84 A 
    7 . 85 89 A 
    4 F 90 .  B 
   20 M 82 85 B 
   25 F 94 94 A 
   14 F 88 84 C 
   ; 
 RUN;
 PROC PRINT data=grade;  
    var subject gender;  *print student ID and gender;
 RUN;

Note: In the upper right-hand corner of the code block you will have the option of copying ( ) the code to your clipboard or downloading ( ) the file to your computer.

*The program starts off with a comment statement that documents the program; 
/******************** 
 This program reads in a set of grades for six 
 students, and prints out their student numbers  
 and genders. 
 *****************/
OPTIONS NODATE LS=78; *A SAS program often begins with output constraints.  Here, with the options statement, the date and time are eliminated from the output and the line size is set to 78; 
 
TITLE "Example: getting started with SAS"; *You can also define a universal title that will appear on each page of your output; 

 DATA grade;*The DATA step wither creates a new SAS dataset or redefines one previously created.  The new SAS dataset created here will be called 'grade'; 
   	InPuT subject gender $ 
exam1 exam2 hwgrade $;*Although the Input Statement is indented erratically, is split across two lines of code and includes a mixture of lower- and upper-case letters, the INPUT Statement is correct and alerts SAS to read observations in five different variables; 
*The $ after 'gender' and 'hmgrade' identify them as character variables; 

   DATALINES; *The DATALINES statement alerts SAS that the data will follow; 
*Missing values are identified with a period (.) for both numeric and character variables.  In the output, a missing value is printed as a period (.), while a missing character value is printed as a blank space; 
   10 M 80 84 A  
    7 . 85 89 A  
    4 F 90 .  B  
   20 M 82 85 B  
   25 F 94 94 A  
   14 F 88 84 C  
   ;  
 RUN; 
*The RUN statements are cues for SAS to process all the code that has come before it. 

PROC PRINT data=grade;   
    var subject gender;  *print student ID and gender; 
*A comment can be included anywhere in the code.  This is often useful for including a reminder or a description of a particular statement or procedure; 
 RUN; 

/******************** 
The program starts off with a comment statement that documents to program:
This program reads in a set of grades for six 
 students, and prints out their student numbers  
 and genders. 
 *****************/ 
 OPTIONS NODATE LS=78; *This statement sets the output to a width of 78 and eliminates the time and date;  

 TITLE "Example: getting started with SAS"; *Establishes a universal title; 

 DATA grade;*The DATA step creates a dataset called 'grade'; 
   	InPuT subject gender $ 
exam1 exam2 hwgrade $; *The data is read in to five variables.  The $ identifies 'gender' and 'hmgrade' as character variables; 
   DATALINES; * Reads in the raw data.  A period (.) identifies missing values; 
   10 M 80 84 A  
    7 . 85 89 A  
    4 F 90 .  B  
   20 M 82 85 B  
   25 F 94 94 A  
   14 F 88 84 C  
   ;  
 RUN;* Executes all the code before it; 

 PROC PRINT data=grade; 
    *A comment can appear anywhere to describe a particular statement or procedure;  
    var subject gender;  *print student ID and gender; 

 RUN; 

At this point, don't worry too much about the details, but you can review what each statement in the program means by clicking on the Inspect the code! button. After you've done that, either download   or copy the code into SAS. Then:

  • Run the program by clicking on the "running man" icon .
  • After the program has run, note that as promised the Output Window moves to the front of the other open SAS windows.
  • Click on the Log Window tab at the bottom of your screen so that the window becomes accessible to you. Review the contents of the window to see the messages that SAS displays. You might want to maximize the window to do so.
  • After you've reviewed the Log Window, you can clear it if you'd like by selecting the Edit menu at the top of your screen, and then selecting Clear All. In general, when you select Clear All, SAS will clear all of the contents of whichever window is currently active.
  • Now, click on the Editor Window tab at the bottom of your screen so that the window becomes accessible to you again. Use your mouse to click on the minus sign that appears just before the PROC PRINT statement. Then, click on the plus sign. In general, clicking on a minus sign collapses the relevant program module, while clicking on a plus sign expands it.
  • Now, use your mouse to select the three lines of code that begin with PROC PRINT and end with RUN. If you click on the "running man" icon  now, SAS will run only the selected code. This can be very helpful to you when you are trying to write and debug just a portion of your program.
  • Now, to save the SAS program, select the File menu along the top of your screen, and then select Save as .... Proceed to save the file in a convenient location just as you would any other Windows file. (Note that SAS saves a SAS program with a ".sas" extension.) You can open the SAS program again by selecting the File menu and then Open Program ...

That should be enough to get you started in using the SAS windowing environment. You will be writing a number of programs throughout the semester, and you'll no doubt get even more familiar with them. For that reason, however, you will want to make yourself a course folder now in which you can save your SAS programs and data sets.


Legend
[1]Link
Has Tooltip/Popover
 Toggleable Visibility