TRANSPOSE Procedure
Example 1: Performing a Simple Transposition
Features: |
PROC TRANSPOSE statement option: OUT=
|
This example performs
a default transposition and uses no subordinate statements.
Program
options nodate pageno=1 linesize=80 pagesize=40;
data score;
input Student $9. +1 StudentID $ Section $ Test1 Test2 Final;
datalines;
Capalleti 0545 1 94 91 87
Dubose 1252 2 51 65 91
Engles 1167 1 95 97 97
Grant 1230 2 63 75 80
Krupski 2527 2 80 76 71
Lundsford 4860 1 92 40 86
McBane 0674 1 75 78 72
;
proc transpose data=score out=score_transposed;
run;
proc print data=score_transposed noobs;
title 'Student Test Scores in Variables';
run;
Program Description
Set the SAS system options. The
NODATE option suppresses the display of the date and time in the output.
PAGENO= specifies the starting page number. LINESIZE= specifies the
output line length, and PAGESIZE= specifies the number of lines on
an output page.
options nodate pageno=1 linesize=80 pagesize=40;
Create the SCORE data set. Set
SCORE contains students' names, their identification numbers, and
their grades on two tests and a final exam.
data score;
input Student $9. +1 StudentID $ Section $ Test1 Test2 Final;
datalines;
Capalleti 0545 1 94 91 87
Dubose 1252 2 51 65 91
Engles 1167 1 95 97 97
Grant 1230 2 63 75 80
Krupski 2527 2 80 76 71
Lundsford 4860 1 92 40 86
McBane 0674 1 75 78 72
;
Transpose the data set. PROC
TRANSPOSE transposes only the numeric variables, Test1, Test2, and
Final, because no VAR statement appears and none of the numeric variables
appear in another statement. OUT= puts the result of the transposition
in the data set SCORE_TRANSPOSED.
proc transpose data=score out=score_transposed;
run;
Print the SCORE_TRANSPOSED data set. The NOOBS option suppresses the printing of observation
numbers
proc print data=score_transposed noobs;
title 'Student Test Scores in Variables';
run;
Output
In the output data
set SCORE_TRANSPOSED, the variables COL1 through COL7 contain the
individual scores for the students. Each observation contains all
the scores for one test. The variable _NAME_ contains the names of
the variables from the input data set that were transposed.
Student Test Scores in Variables
Student Test Scores in Variables 1
_NAME_ COL1 COL2 COL3 COL4 COL5 COL6 COL7
Test1 94 51 95 63 80 92 75
Test2 91 65 97 75 76 40 78
Final 87 91 97 80 71 86 72
Copyright © SAS Institute Inc. All rights reserved.