The PROC TRANSPOSE technique in SAS (Statistical Analysis System) is used to convert data from a “long” format to a “wide” format or vice versa. It is especially handy when you need to rearrange your data so that it may be used for different sorts of studies or reporting. PROC TRANSPOSE is a strong SAS tool for reshaping data that is extensively used in data analysis and reporting for a variety of data manipulation activities.
PROC TRANSPOSE DATA=input_data OUT=output_data;
ID Subject; /* Unique values in ‘Subject’ become new variable names */
VAR Score; /* Values in ‘Score’ are transposed */
BY Group; /* Optional: Transpose data within each ‘Group’ */
RUN;
Basic Syntax of proc transpose
PROC TRANSPOSE DATA=input_data OUT=output_data;
BY variable(s);
ID variable(s);
VAR variable(s);
COPY variable(s);
PREFIX prefix_string;
DELIMITER delimiter_character;
RUN;
DATA=input_data: This specifies the input dataset to be transposed.
OUT=output_data: The name of the output dataset where the transposed data will be stored is specified.
Optional BY variable(s). Specifies one or more variables that define data groupings. If your data is organised into groups, you may use the BY statement to transpose data inside each group.
ID variable(s): Specifies the variable(s) whose unique values will become the transposed dataset’s new variable names.
VAR variable(s): Indicates which variables’ values to be transposed from rows to columns (or vice versa).
Variable(s) to COPY: Optional. Specifies which variables should be transferred to the output dataset without being transposed.
PREFIX prefix string: This is optional. Provides a prefix to be appended to the new variable names formed during the transposition.
Optional delimiter character for DELIMITER. Specifies the character that will be used to separate the old variable name from the values in the new variable names.