A Simple Example
Before getting started on the technical details of SAS programming, we'll look at a simple example.
When you open SAS, you will see something similar to the picture below. The three windows on the right, Log, Output, and Editor, will most likely be overlapping. Here they have been arranged so you can see them all. Below these windows there is a task bar with buttons that allows easy switching between windows. The log contains a record of what SAS does, together with error messages and other information. At this point there is already some information in the Log relating to the startup process. On the left, you see a pane called Explorer. Notice there are tabs at the bottom. This pane can be switched between Explorer and Results.
Now suppose we have some data on course grades and percent attendance, as follows:
Let's analyze this data.
First, we have to get the data into SAS. Here's a way to do it:
This SAS program will create a dataset called "grades" with two variables called "grade" and "attend." There are nine observations. Type this program into the editor, then submit it by clicking the "running man" icon in the toolbar. The log will show some notes about the creation of the dataset.
This is the only result you can immediately see from running this program. It doesn't produce any output, it just creates a dataset. It is important to check the log when running a program like this, or you may not know if it has run correctly.
The existence of the dataset can also be verified by looking at the explorer pane on the right. Double-click the file-cabinet icon called Libraries, then the file-drawer icon called Work. You will see a spreadsheet-like icon called "Grades." You can also double-click this icon to open a spreadsheet view of the data.
Now that we have data in SAS, what can we do with it? Lots of things, of course! But this is a simple example. We will demonstrate two of the most commonly used procs (procedures) in SAS. The first is proc print. This will produce formatted output with headings, page numbers, page breaks, and so forth, suitable for printing. It doesn't actually send the output to the printer, but displays it in the output window. The second is proc plot, which is used for producing simple scatterplots of two variables. The commands for these procedures are shown below, together with the commands that create the dataset.
The results of proc print and proc plot will be shown in the output window, and will look something like this (examples here are modified to reduce the size):
That's the end of our simple example. Now we're ready to begin in earnest!