How to Label Variables in SAS (With Example)

Labelling variables in SAS is an important step in ensuring data integrity and accuracy in your analysis. To do this, use the LABEL statement to assign descriptive labels to the variables in your dataset. As an example, you could use the LABEL statement to assign the label “Gender” to a variable that is coded as 0 for male and 1 for female. This makes it easier to understand the data when looking through your output.


You can use the label function in SAS to provide label names to variables in a dataset.

The following example shows how to use this function in practice.

Example: Label Variables in SAS

Suppose we create the following dataset in SAS:

/*create dataset*/
data data1;
    input ID $ x y;
    datalines;
Mavs 99 21
Spurs 93 18
Rockets 88 27
Thunder 91 29
Warriors 104 40
Cavs 93 30
;
run;

/*view contents of dataset*/
proc contents data=data1;
run;

The output of the proc contents function shows us the name, data type, and length of each of the three variables in our dataset.

However, it might not be obvious what ID, x, and y actually refer to in the dataset.

Fortunately, we can use the label function when creating the dataset to provide specific labels for each variable:

/*create dataset*/
data data1;
    input ID $ x y;
    label ID = 'Team' x = 'Points' y = 'Rebounds';
    datalines;
Mavs 99 21
Spurs 93 18
Rockets 88 27
Thunder 91 29
Warriors 104 40
Cavs 93 30
;
run;

/*view contents of dataset*/
proc contents data=data1;
run;

label variables in SAS

Notice that the output of proc contents now contains an extra column called label, which contains the labels for the three variables that we specified.

The following tutorials explain how to perform other common tasks in SAS:

x