step to assign labels to the variables

  • Author: admin
  • Filed under: Auto-cars
  • Date: Mar 12,2008

Creating variable labels We use the label statement in the data step to assign labels to the variables.  You could also assign labels to variables in proc steps, but then the labelsonly exist for that step.  When labels are assigned in the data step they are available for all procedures that use that data set.

The following program assigns variable labels to rep78, mpg and foreign.
DATA  auto2;   SET auto;   LABEL  rep78  =”1978 Repair Record”          mpg    =”Miles Per Gallon”          foreign=”Where Car Was Made”;RUN;PROC CONTENTS DATA=auto2;RUN;


Looking at the output produced by the proc contents step shows that the labels were indeed assigned.  

 The relevant part of this output follows.
—–Alphabetic List of Variables and Attributes—–#    Variable    Type    Len    Pos    Label———————————————————5    FOREIGN     Num       8     32    Where Car Was Made1    MAKE        Char      8      02    MPG         Num       8      8    Miles Per Gallon3    REP78       Num       8     16    1978 Repair Record4    WEIGHT      Num       8     24

These labels will also appear on the output of other procedures giving a fuller description of the variables involved.  This is demonstrated in the proc means below.
PROC MEANS DATA=auto2;RUN;


Looking at the output produced by the proc means shows that the labels were indeed assigned.  Look at the column titled Label. The relevant part of this output follows.
Variable  Label                N       Mean  Std Dev    Minimum————————————————————–MPG       Miles Per Gallon    26 20.9230769   4.7575042    14REP78     1978 Repair Record  24  3.2916667   0.8064504     2WEIGHT                        26    3099.23 695.0794089  2020FOREIGN   Where Car Was Made  26  0.2692308   0.4523443     0




Leave a comment

You must be logged in to post a comment.