Exercises: Using SAS - Windows and Files

Doug Hemken

February 2017

Having read the introductory material, here is a little self-test. The main points are that you know how to type and submit commands in SAS, and that you know how to save all the files associated with your simple project.

  1. Save a Data Set

On the "Y" drive (aka TEMP30DAYS), in the "SAS" folder is a data set named "class". This has data about the heights and weights of a group of younger teenagers.

Using SAS, calculate the body mass index for each person, and make a copy of this data set on your "U" drive.

\(BMI = (\frac{weight}{height^2})\times703\)

Hint: you'll need a DATA step. The first few observations will look like this:

        Obs     Name      Sex    Age    Height    Weight      bmi

          1    Alfred      M      14     69.0      112.5    16.6115
          2    Alice       F      13     56.5       84.0    18.4986
          3    Barbara     F      13     65.3       98.0    16.1568
          4    Carol       F      14     62.8      102.5    18.2709
          5    Henry       M      14     63.5      102.5    17.8703
  1. Descriptive Statistics, Saving Output

Calculate the average BMI for this group. Save your output (any format you like, for this exercise).

Here is my result. More output, and output formatted differently is fine.

                            The MEANS Procedure

                         Analysis Variable : bmi 
  1. Save a Log

Which took the computer longer, the DATA step or the PROC step? Save your log.

Your times will almost certainly be different than mine! (Also, I'm not reading data from the Y drive, nor am I writing it to the U drive, so you can't just copy-and-paste this.)

2          data class;
3            set sashelp.class;
4            bmi = (weight/height**2)*703;
5            run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CLASS has 19 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

7          proc means data=class mean;
8            var bmi;
9            run;

NOTE: There were 19 observations read from the data set WORK.CLASS.
NOTE: The PROCEDURE MEANS printed page 1.
NOTE: PROCEDURE MEANS used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds
  1. Viewing Data

Who has the largest BMI? You can answer this by either looking at the data set in the software ("by hand") or by writing code. For either solution, I'd suggest SORTing your data first.

My answer is

                               Obs     Name

                                 1    Robert
  1. Save the Commands

Save the SAS code you have used to this point.

Two bonus questions: if you are already familiar with SAS, try these two additional exercises.

(B1) Scatterplot

Produce a scatterplot of BMI by age by sex. Save the graph to your U drive. Hint: PROC SGPLOT, although there are several other graphics procedures that will also do this.

(B2) More New Variables

Are any of the kids here underweight? obese? The CDC has sex-and-age specific guidelines for these terms (this will require you to look up a few things).