Skip to main content
v2026.11,858 entries · CC-BY 4.0

PROC TRANSPOSE in SAS: Syntax, Options and Output Explained

How PROC TRANSPOSE in SAS works: syntax, BY/ID/VAR roles, default names, data-type rules and duplicate-ID behaviour, with a documented example.

Written and maintained by CASRAI Editorial Board

Last updated

PROC TRANSPOSE in SAS creates a new data set by restructuring the values of an existing one: the variables you select become observations (rows) in the output. Used with the BY, ID and VAR statements, it is the standard SAS procedure for turning a wide data set into a long one, or the reverse. This guide covers the syntax, the naming and data-type rules that decide what the output looks like, and what happens when an ID variable contains duplicates. Statements below are taken from the SAS Base Procedures Guide (documentation checked 2026-10-29); the SAS version you run may differ in details, so treat the current SAS documentation as the final word on your installation.

What PROC TRANSPOSE is used for in research

SAS describes the procedure as one that creates “an output data set by restructuring the values in a SAS data set, transposing selected variables into observations.” In research data work the usual reason is a shape mismatch: a survey or repeated-measures file arrives with one column per time point or per item, while the analysis step expects one row per measurement (or the other way round). Moving between those shapes is the same task described in the tidy data rules for structuring research data, and the choice of shape also depends on the types of variables you are working with.

The procedure has five statements besides PROC TRANSPOSE itself, each with one job (wording from the SAS syntax summary):

  • BY – transpose each BY group separately.
  • COPY – copy variables directly into the output without transposing them.
  • ID – name the transposed variables from the values of a variable.
  • IDLABEL – create labels for the transposed variables.
  • VAR – list the variables to transpose.

Install or access (official source only)

PROC TRANSPOSE is a Base SAS procedure, documented in the Base SAS Procedures Guide. SAS software is supplied by SAS Institute; start from sas.com. The official reference for every statement and option is the SAS documentation at documentation.sas.com; the older Base SAS 9.3 Procedures Guide pages cited on this page remain available at support.sas.com.

Step-by-step: transposing a data set in SAS

1. Write the PROC TRANSPOSE statement

The full statement, as given in the SAS documentation, is:

PROC TRANSPOSE <DATA=input-data-set> <DELIMITER=delimiter> <LABEL=label>
               <LET> <NAME=name> <OUT=output-data-set>
               <PREFIX=prefix> <SUFFIX=suffix>;
  BY <DESCENDING> variable(s) <NOTSORTED>;
  COPY variable(s);
  ID variable;
  IDLABEL variable;
  VAR variable(s);
RUN;

DATA= names the data set to transpose; if you omit it, SAS uses the most recently created data set. OUT= names the output data set; if the data set does not exist, the procedure creates it with the DATAn naming convention (DATA1, DATA2, and so on). Always set both explicitly so the step does not depend on what ran before it.

2. Choose the variables to transpose with VAR

List the variables to transpose in a VAR statement. If you leave the VAR statement out, SAS documentation states that the procedure transposes only the numeric variables. If a character column is absent from your output, a missing VAR statement is the first thing to check.

3. Name the new columns with ID, PREFIX= and SUFFIX=

An ID statement names a variable whose values become the names of the transposed variables. With PREFIX=, the new name begins with the prefix followed by the ID value; with SUFFIX=, the suffix is appended to the ID value. If you specify more than one ID variable, DELIMITER= sets what is inserted between their values.

4. Add BY, COPY and IDLABEL as needed

BY transposes each BY group rather than the data set as a whole. COPY carries variables across unchanged. IDLABEL takes its labels for the transposed variables from the values of another variable.

5. A worked example from the SAS documentation (proc transpose sas example)

The SAS documentation’s “Labeling Transposed Variables” example uses a data set named SCORE with a StudentID, a Student name, and numeric variables Test1, Test2 and Final:

proc transpose data=score out=idlabel name=Test prefix=sn;
   id studentid;
   idlabel student;
run;

No VAR statement appears, so SAS transposes only the numeric variables Test1, Test2 and Final. NAME=Test sets the name of the variable that holds the original variable names. PREFIX=sn plus the ID value forms each new variable name (for example sn0545). IDLABEL student labels each new variable with the student’s name, and the labelled output looks like this:

NAME OF FORMER VARIABLE Capalleti Dubose Engles Grant Krupski Lundsford McBane
Test1 94 51 95 63 80 92 75
Test2 91 65 97 75 76 40 78
Final 87 91 97 80 71 86 72

Source: SAS Base Procedures Guide, TRANSPOSE Procedure, Example 3 (checked 2026-10-29). Each original variable (Test1, Test2, Final) became a row; each student became a column.

6. Print the result yourself

PROC TRANSPOSE does not print the output data set. Follow it with PROC PRINT (the SAS example uses PROC PRINT with the LABEL option to show variable labels as column headings) or PROC CONTENTS to inspect the new variable names, types and labels.

Output and how to read it

Default names: COL1 to COLn, _NAME_ and _LABEL_ (proc transpose sas)

The output variable names depend on what you specify. According to the SAS documentation:

  • With no ID statement, no PREFIX= and no _NAME_ variable in the input, the procedure names the transposed variables COL1, COL2, …, COLn.
  • The output contains a variable named _NAME_ by default, holding the names of the variables that were transposed. NAME= renames it (the example above uses NAME=Test).
  • The variable that holds each transposed variable’s label is named _LABEL_ by default. LABEL= renames it.
  • In the IDLABEL example, the _NAME_ variable carries the label “NAME OF FORMER VARIABLE” when no other label is supplied.

Data types of the transposed variables

The type rule matters for later analysis steps. SAS documentation (the archived TRANSPOSE Results page) states that if all variables being transposed are numeric, the transposed variables are numeric; if any variable being transposed is character, all transposed variables are character. The length of the transposed variables equals the length of the longest variable being transposed. Mixing a character variable into the VAR list therefore turns every transposed column into text.

Because column names and types change between runs of a transposition, record the resulting structure in a codebook (see the DDI Codebook entry) and keep the step in your script so the reshaping is repeatable; this is part of computational reproducibility.

Troubleshooting

Duplicate ID values: the warning and LET

Each value of an ID variable must be unique (within a BY group if you use BY). The SAS documentation states that duplicate values cause PROC TRANSPOSE to issue a warning message and stop. If you add the LET option, the procedure allows duplicates and transposes the observation that contains the last occurrence of that ID value within the data set or BY group. Because only the last occurrence is transposed, check why the duplicates exist before using LET.

A column is missing from the output

If there is no VAR statement, only numeric variables are transposed. Name character variables in a VAR statement, or use COPY if you only need them carried through unchanged.

The new variables are all character

One character variable in the transposed set makes every transposed variable character (see the type rule above). Transpose numeric and character variables in separate steps if you need the numbers to stay numeric.

The output is not in a report

The procedure creates a data set only. The SAS overview also notes that PROC TRANSPOSE does not support the Output Delivery System, so print the output data set with another procedure.

Unexpected variable names

Names come from PREFIX=, SUFFIX= and the ID values, as described in step 3; without any of these you get COL1 to COLn. Set the naming options explicitly and use PROC CONTENTS to confirm.

Free alternatives (table)

Other open-source tools reshape data between wide and long formats. They are separate tools with their own syntax and defaults, so check each one’s documentation rather than assuming it matches PROC TRANSPOSE.

Tool and function What its documentation says it does
R, tidyr: pivot_longer() Pivot data from wide to long; it makes the data longer, with more rows and fewer columns.
R, tidyr: pivot_wider() Pivot data from long to wide; it makes the data wider, with more columns and fewer rows.
Python, pandas: melt() Unpivot a DataFrame from wide to long format, optionally leaving identifiers set.

Sources: tidyr reference pages for pivot_longer and pivot_wider, and pandas.melt reference page (all checked 2026-10-29).

FAQ

What does PROC TRANSPOSE do in SAS?

It creates an output data set by restructuring the values in a SAS data set, transposing selected variables into observations. The BY, COPY, ID, IDLABEL and VAR statements control which variables are transposed, how the new variables are named and labelled, and what is copied across.

Is there a proc transpose SAS example I can start from?

Yes. The worked example above, from the SAS documentation, transposes three numeric score variables into rows and uses a student ID to name the new columns. Run it against your own data with your own variable names.

Why are my transposed columns called COL1, COL2 and so on?

When there is no ID statement, no PREFIX= option and no _NAME_ variable in the input, SAS assigns the names COL1 through COLn. Add an ID statement or PREFIX= to control the names.

What happens if my ID variable has duplicates?

PROC TRANSPOSE issues a warning and stops. With the LET option it continues and keeps the last occurrence of each ID value in the data set or BY group.

Sources (official documentation)

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about PROC TRANSPOSE in SAS: Syntax, Options and Output Explained

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.