18 C
London
Thursday, July 24, 2025
HomeSASData Munging in SASHow to Use PROC TRANSPOSE in SAS (With Examples)

How to Use PROC TRANSPOSE in SAS (With Examples)

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 PROC TRANSPOSE in SAS to quickly transpose a dataset from a long format to a wide format.

This function uses the following basic syntax:

proc transpose data=long_data out=wide_data;
    by var1;
    id var2;
    var var3;
run;

where:

  • by: The variable to place along the rows
  • id: The variable to place along the columns
  • var: The variable whose values are placed within the dataset

The following example shows how to use PROC TRANSPOSE in practice.

Example: How to Use PROC TRANSPOSE in SAS

Suppose we have the following dataset in a long format in SAS:

/*create dataset in long format*/
data long_data;
    input team $ variable $ value;
    datalines;
A Points 88
A Assists 12
A Rebounds 22
B Points 91
B Assists 17
B Rebounds 28
C Points 99
C Assists 24
C Rebounds 30
D Points 94
D Assists 28
D Rebounds 31
;
run;

/*view dataset*/
proc print data=long_data;

We can use PROC TRANSPOSE to convert this dataset from a long format to a wide format:

/*create new dataset in wide format*/
proc transpose data=long_data out=wide_data;
    by team;
    id variable;
    var value;
run;

/*view wide data*/
proc print data=wide_data;

Notice that this dataset contains the same information as the previous dataset, but it’s simply displayed in a wide format.

By default, SAS creates a _NAME_ variable that shows which variable is used for the values in the  dataset.

Feel free to use the DROP statement to drop this variable when using PROC TRANSPOSE:

/*create new dataset in wide format*/
proc transpose data=long_data out=wide_data(drop=_name_);
    by team;
    id variable;
    var value;
run;

/*view wide data*/
proc print data=wide_data;

Notice that the _NAME_ variable has been dropped from the dataset.

Additional Resources

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

How to Use Proc Summary in SAS
How to Use Proc Tabulate in SAS
How to Create Frequency Tables 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