Table of Contents
PROC TRANSPOSE is a powerful SAS procedure that allows for the transformation of data from a vertical to a horizontal format, or vice versa. This procedure is particularly useful in situations where data needs to be restructured or rearranged for easier analysis and reporting. By specifying the appropriate variables and options, PROC TRANSPOSE can efficiently transpose data tables, merge data sets, and create new variables. It also offers various options for handling missing values and duplicate observations. Overall, PROC TRANSPOSE provides a flexible and efficient method for manipulating data in SAS and can greatly enhance data analysis and reporting capabilities.
Use PROC TRANSPOSE in SAS (With Examples)
You can use PROC TRANSPOSE in SAS to quickly transpose a dataset from a .
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 printdata=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 transposedata=long_data out=wide_data;
by team;
id variable;
var value;
run;
/*view wide data*/
proc printdata=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 transposedata=long_data out=wide_data(drop=_name_);
by team;
id variable;
var value;
run;
/*view wide data*/
proc printdata=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:
Cite this article
stats writer (2024). How can PROC TRANSPOSE be used in SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-proc-transpose-be-used-in-sas/
stats writer. "How can PROC TRANSPOSE be used in SAS?." PSYCHOLOGICAL SCALES, 1 Jul. 2024, https://scales.arabpsychology.com/stats/how-can-proc-transpose-be-used-in-sas/.
stats writer. "How can PROC TRANSPOSE be used in SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-proc-transpose-be-used-in-sas/.
stats writer (2024) 'How can PROC TRANSPOSE be used in SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-proc-transpose-be-used-in-sas/.
[1] stats writer, "How can PROC TRANSPOSE be used in SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, July, 2024.
stats writer. How can PROC TRANSPOSE be used in SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
