Return to Homepage

Goto the Tip of the Month Archive

Other interesting pages ...
LinkedIn Profile
SAS Cheat Sheet
Useful SAS Code
Full SAS Example
Basic Statistics
Contact Information

SAS Tip of the Month
May 2016

From where we left off last month, now why is the label useful. As you can see already it gives a useful description of what the variable is. Now lets extend that to a small report using the PRINT procedure:

   proc print data=class noobs;
   run;

that produces the following output (abridged):

   Name       Sex    Age    Height    Weight
   
   Alfred      M      14     69.0      112.5
   Alice       F      13     56.5       84.0
   Barbara     F      13     65.3       98.0
   Carol       F      14     62.8      102.5
   Henry       M      14     63.5      102.5

The column headers are the same as the variable names, and we have the same problem of not knowing what the units are for Age, Height and Weight (but did we not put that in a label earlier) but lets add another option to get the labels:

   proc print data=class noobs LABEL;
   run;

that produces the following output (abridged):

                 Age (years)  Height (in)   Weight (kg)
                  at Start     at Start      at Start
  Name     Sex    of Study     of Study      of Study
 
  Alfred     M         14         69.0          112.5
  Alice      F         13         56.5           84.0
  Barbara    F         13         65.3           98.0
  Carol      F         14         62.8          102.5
  Henry      M         14         63.5          102.5

Now, as you can see, we have a report that gives a clear description of the variables though the use of dataset variable labels. There will be those reading this who will say that I could have put the label in the PRINT procedure call (yes, the LABEL statement is a global statement that can be used in almost any procedure) and would be done this way using the following code:

   proc print data=class noobs LABEL;
         label weight='Weight (kg) at Start of Study'
               height='Height (in) at Start of Study'
               age='Age (years) at Start of Study';
   run;

But the one reason I don't normally use this method is that the label does not carry forward in the dataset. Now see a complete example where the CLASS data is copied from the SASHELP directory, useful labels put on the dataset, then doing a PRINT, MEANS and TABULATE call on the same data, all with the same labels:

   proc datasets library=work;
      copy in=sashelp out=work;
         select class;
      modify class;
         label weight='Weight (kg) at Start of Study'
               height='Height (in) at Start of Study'
               age='Age (years) at Start of Study';
      quit;
   run;
   proc print data=class noobs LABEL;
   run;
   proc means data=class;
      var age height weight;
   run;
   proc tabulate data=class;
      class sex;
      var age height weight;
      tables age*
               (n*f=8.0 mean*f=8.2 std*f=8.3
                median*f=8.2 min*f=8.0 max*f=8.0)
             (height weight)*
               (n*f=8.0 mean*f=8.3 std*f=8.4
                median*f=8.3 min*f=8.1 max*f=8.1),
             sex all='Total';
   run;

produces the following output (abridged):

                 The PRINT Procedure

                    Age (years)    Height (in) Weight (kg)
                      at Start       at Start   at Start
   Name      Sex      of Study       of Study   of Study

   Alfred     M          14            69.0          112.5
   Alice      F          13            56.5           84.0
   Barbara    F          13            65.3           98.0


                  The MEANS Procedure

   Var    Label                         N Mean STD Min Max      
   Age    Age (years) at Start of Study 19  13  1   11  16
   Height Height (in) at Start of Study 19  62  5   51  72
   Weight Weight (kg) at Start of Study 19 100 23   51 150


                The TABULATE Procedure

   ----------------------------------------------------
   |                       |       Sex       |        |
   |                       |-----------------|        |
   |                       |   F    |   M    | Total  |
   |-----------------------+--------+--------+--------|
   |Age (years)|N          |       9|      10|      19|
   |at Start of|-----------+--------+--------+--------|
   |Study      |Mean       |   13.22|   13.40|   13.32|
   |           |-----------+--------+--------+--------|
   |           |Std        |   1.394|   1.647|   1.493|
   |           |-----------+--------+--------+--------|
   |           |Median     |   13.00|   13.50|   13.00|
   |           |-----------+--------+--------+--------|
   |           |Min        |      11|      11|      11|
   |           |-----------+--------+--------+--------|
   |           |Max        |      15|      16|      16|
   |-----------+-----------+--------+--------+--------|
   |Height (in)|N          |       9|      10|      19|
   |at Start of|-----------+--------+--------+--------|
   |Study      |Mean       |  60.589|  63.910|  62.337|

Note that the label we defined in the DATASETS procedure carried forward to the PRINT, MEANS and TABULATE procedures.

See you next month.

________________________________
Updated May 2, 2016