STAT 330


Introduction to SAS on Macs

To run SAS in the Assignment Lab on a Macintosh computer you should turn on the computer if necessary, and let it run through its initial set-up. You will be asked for your CCN id and password -- these are your UNIX id (from AD1066 if you don't have it yet) and password. Type them in the two spaces provided and hit RETURN or ENTER after each. The machine will then prompt you for your assignment lab id and password. The id is STAT_330_D1_RLOC for me in section 1 of STAT 330. Your id will be the same except that RLOC is the first letter of your first name followed by the first three letters of your surname. Then enter your password. Yours is the first seven digits of your SFU ID. You should, some time soon, explore the menus to find a way to change your password to something more secure. Once you are signed on, you will see a screen with various little pictures, (called ICONS) and a menu bar across the top. You will need to double click (depress the button on the mouse twice in fairly rapid succession while holding the mouse cursor over top of the icon) the ICON called SFU_ASST.MAC. A window will open and you must find the folder labelled SAS610 and double click this. Again a window will open and you should double click the SAS icon. This will activate SAS. A small clock will replace the cursor momentarily if you have succeeded. However, it may revert back to the arrow and appear to be hung up. Be patient. SAS is a large program that may take up to several minutes to get running under heavy simultaneous demand.

If you have a UNIX account with access to Beaufort, you can run SAS on that machine as well. Experienced SAS users often find the UNIX environment more convenient.

Once you get SAS running on a Mac, you should have a screen with three windows, called child windows. Two will be plainly visible. These are the log window at the top, and the program editor window at the bottom. You may see a section between these of another window. This is the output window, hidden in the background behind the other two. (On a Mac there may also be a little palette with various pictures on it; this palette can be used to change between windows; I usually click on the tiny ``go-away'' box in the upper left hand corner. ) When you run a successful set of SAS commands, the output window will automatically pop to the front.

Practice first moving from window to window and pulling down menus. You put the mouse on top of one of the words at the top and press the mouse button. A menu of possible selections will appear. You pull the mouse down and different menu items will turn black (become "highlighted"). If you let go of the button while an item is highlighted that item will be selected. One of the menus, called Windows, contains a list of the available windows and you can use that menu to move between windows. The window out front whose title bar (at the top of the window) has dark writing and lines running across is ``active'' and the menus at the top of the screen refer to that window.

Now activate the program editor window. You can use this window to enter your program, and can include the data in the program as well. However, it is typically more convenient to use a separate data file. We shall first use the program editor window to create and store such a file.

Use the mouse to position the cursor near the upper left-hand corner of the program editor window, and click the mouse button. You should aim for the left-hand end of the second line. If the next step fails, then move the cursor down slightly. Enter the following lines of data, moving to the next line down each time with the return key. To save space, the data are printed below in two sets of two columns each. Your screen should contain one set of two, long columns.

             M  13.3                           F 30
             F  23.2         As one            M 21
             M  24           set of            M  8
             F  22                             F 12
             M  20           t   c             F 23
             M  19           w   o             F 21.7
             F  21           o   l             M 12
             F  26               u             M 18
             M  31           l   m             M 22
             M  20           o   n             M 12
             F  28           n   s             M 16
             F  16           g

Check your work. Use the ``page-up'' and ``page-down'' keys (or the scroll bar if you know how to use it) if necessary. (WARNING: if, when you push page-up or page-down you just get numbers typed check to see if the green light labelled num lock is on; if so find the key marked num lock on the number pad and push it once to make that light go off.) If you find a mistake, use the arrow keys or mouse to move the cursor to the error, and correct it. You can use the delete or backspace keys to delete an error, and can enter an entire new line if you want. Try making a few changes, even if your data entry has been perfect.

Once you are satisfied with the data, you can file them away. To do this, pull down the file menu while the Program Editor window is active and select Save as by pulling the mouse out the right hand end of Save as past the little black triangle. This produces a sub-menu from which you select Write to file .... A dialog box will open up. You need to type in the name of the file in the appropriate little box; I suggest the name raw.dat. You must save it either temporarily in the folder Student Folder with the disk Macintosh HD or permanently on a floppy disk which you put in the disk drive. The dialog box has ways of moving around the file directories to find the place I mean. The easiest way to begin is to click on the button Desktop. Your floppy disk should be listed as one of the things in the little window in the dialog box after this; Macintosh HD should be there too.

You can now type in SAS commands for analyzing the data. (The data are a shuffled version of the data set on pages 23 and 176 of the SAS System for Elementary Statistical Analysis, and are measurements of percent body fat for 13 males and 10 females in a fitness center.) We shall ask SAS to sort these data by sex, and to make some summary statements for each group.

First, you will want to clear the text from the Program Editor window. While that window is active pull down the Edit menu and select Clear all. Now, move the cursor to the start of the first line in the Program Editor window, and type lines of code so as to make the following screen display. Note that a SAS line always ends with a semi-colon.

   options pagesize=60 linesize=80;
   data bodyfat;
   infile 'myfloppy:raw.dat';
   input sex $ fatpct;
   proc print;
   run;

If you did not already erase the numbers from the subsequent lines, you can do so now by typing blanks on top of them, or by marking text by dragging the mouse over segments to be deleted with the mouse button depressed, and then using the delete key to delete the marked portions. Check your entered lines, and edit where needed. Their purpose is as follows:

  1. The options line sets the output to a size suitable for printing on a standard printer.
  2. The data line provides a label. It is mandatory in any SAS analysis.
  3. The infile line tells SAS the name of the file from which to read data; in this case I am assuming the file was saved on a floppy disk named myfloppy. If you had saved it in the student folder the file name would be 'Macintosh HD:Student Folder:raw.dat'. SAS can also read data directly from a program listing with a cards command, or from a previously created SAS file with a special file extension and format. The file name must be enclosed in single quotes. If you forget one of these, SAS will treat all the text following the unmatched quote as character text, not as SAS statements. This includes all subsequent commands submitted later. To get out of this mess, you need to submit a new, single quote. Try to avoid this frustrating error.
  4. The input command tells SAS what variables it is to read from the file. The symbol, $, after the first variable name specifies that it is what is called a character variable. This means that it contains symbols that are used solely to identify an attribute like sex, treatment used, etc. The format of the input command has considerable flexibility and power. The above is the simplest version.
  5. Proc is a SAS abbreviation for a procedure. The print procedure invoked here prints a copy of the data to the output window.
  6. The run command tells SAS to execute the instructions in the previous set of lines.

Once you are satisfied with the program lines, pull down the Locals menu while the Program Editor window is active, and select the item, Submit to instruct SAS to process these lines. Watch the log window. It should display a log of your session, including any possible errors. It may take a while. Again, be prepared to wait. If you did not make an error, you should see the output window pop into the foreground. If not, and the contents of the log window go by too rapidly, you can move the cursor to it (by using the mouse or Windows menu). Then use the page-up key or the scroll bar on the right-hand border of the window to review the previous components of the log. (You use the mouse to activate the scroll bar. Experiment with it if you have never used a scroll bar before, and see if you can get it to work.)

If you made an error, you will have to try again. You can do this by recalling the previously submitted lines. This in turn is done by activating the Program Editor window, and pulling down the Locals menu, and selecting Recall from the menu that appears. Then try to correct the error. (This is undoubtedly the most frustrating part of using SAS. If a more experienced user owes you a favour or two, you might want to call in some assistance. The SAS manuals are so extensive, that it is hard for the beginner to know where to look for help. In particular, see the comments on unbalanced quotes in item 3 above.)

Assuming that you did not make an error, you should see the data printed in the output window. You can now proceed to the sorting and production of summaries. Move the cursor to near the upper left-hand corner of the Program Editor window, and type lines of code to create the following display:

   proc sort data=bodyfat;
   by sex;
   proc means data=bodyfat;
   by sex;
   var fatpct;
   run;

Check these lines for accuracy and edit where necessary. Their purpose is as follows:

  1. Proc sort is the procedure for sorting data.
  2. The by statement specifies that the sorting is to be done according to the values of the variable, sex.
  3. Proc means produces basic descriptive statistics.
  4. The by statement instructs SAS to do the calculations for each sex separately.
  5. The var statement tells SAS which variable the summaries are to be computed for.
  6. These are terminated by a run command to instruct SAS to execute the entire set of commands.
Once you are satisfied with the program lines, use the Submit option from the Locals menu in the Program Editor window to submit them.

Unless you goofed, the output window will have again popped to the foreground. Examine the results. The page-up and page-down keys or scroll bar will help you move up and down through the display.

Now return to the program editor window, and type in the following lines:

   proc chart data=bodyfat;
   vbar fatpct/group=sex;
   title 'Crude Side-by-Side Histograms';
   run;
Then Submit them using the Locals menu.

You should by now be able to guess the role of each of the above statements. See if you can predict the results of changing in the second line, (i) vbar to hbar, and (ii) deleting the optional portion, /group=sex. Check your intuition by recalling the former statements to the programme editor, modifying the second line, and re submitting the lines to SAS. To save the results in a file, make the Output window active. Pull down the File menu and select Save as, and then Write to file. Then do as you did when saving the data, typing in some file name like results.

You can print a copy of the output using the Print option from the File menu on the Output window, as long as you have a printing card for using the local printer. You can also take the diskette with you to another Mac with a printer, and print it there.

You can, of course, also file a copy of your commands, edit them elsewhere, and then, with the Open option in the File menu on the Program Editor window, incorporate them into a subsequent analysis. This is one of the major advantages of SAS. It makes it relatively easy to do repetitive, identical or very similar analyses. A later exercise will give practice in this skill.

When you are finished running SAS, pull down the File menu and select Exit .... Confirm your choice when asked. Then select the File menu from the Finder window, and from it, Logout. Again, confirm your choice.

Pages with examples of individual procedures
  1. Doing Simple Linear Regression vi proc glm. This example also shows normal probability plots and how to save the residuals as a SAS data set.
  2. Doing Multiple Linear Regression vi proc glm. More residual plots.
  3. Doing one-way ANOVA vi proc anova. Also illustrates multiple comparison procedures.
  4. Doing two way ANOVA vi proc anova. More multiple comparisons.

Manuals

SAS produces an intimidating set of manuals. You may find the following useful:

  1. SAS System for Elementary Statistical Analysis.
  2. SAS Companion for the Microsoft Windows Environment, Version 6, First Edition.
  3. SAS Companion for the UNIX Environment and Derivatives.
  4. SAS/STAT User's Guide, Volumes 1 & 2. (Comprehensive discussion of the procedures for doing statistical analyses.)
  5. SAS/GRAPH Software: Introduction. (Good introduction to the more comprehensive, two-volume user's guide for creating high-quality graphs.)

Written by R. Lockhart on Sept 9, 1996, based on notes for PC's by C. B. Dean


Richard Lockhart
Thu Sep 12 22:40:35 PDT 1996