4 C
London
Friday, December 20, 2024
HomeSASData Munging in SASHow to Label Variables in SAS (With Example)

How to Label Variables in SAS (With Example)

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

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.

Additional Resources

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

How to Normalize Data in SAS
How to Replace Characters in a String in SAS
How to Replace Missing Values with Zero in SAS
How to Remove Duplicates in SAS

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories