TRANSPOSE Procedure

Example 3: Labeling Transposed Variables

Features:

PROC TRANSPOSE statement option: PREFIX=

IDLABEL statement

Data set: SCORE
This example uses the values of the variable in the IDLABEL statement to label transposed variables.

Program 1

options nodate pageno=1 linesize=80 pagesize=40;
proc transpose data=score out=idlabel name=Test
     prefix=sn;
   id studentid;
     idlabel student;
run;
  proc print data=idlabel label noobs;
     title 'Student Test Scores';
  run;
proc contents data=idlabel;
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;
Transpose the data set. PROC TRANSPOSE transposes only the numeric variables, Test1, Test2, and Final, because no VAR statement appears. OUT= puts the result of the transposition in the IDLABEL data set. NAME= specifies Test as the name for the variable that contains the names of the variables in the input data set that the procedure transposes. The procedure names the transposed variables by using the value from PREFIX=, sn, and the value of the ID variable StudentID.
proc transpose data=score out=idlabel name=Test
     prefix=sn;
   id studentid;
Assign labels to the output variables. PROC TRANSPOSE uses the values of the variable Student to label the transposed variables. The procedure provides the following as the label for the _NAME_ variable:NAME OF FORMER VARIABLE
     idlabel student;
run;
Print the IDLABEL data set. The LABEL option causes PROC PRINT to print variable labels for column headings. The NOOBS option suppresses the printing of observation numbers.
  proc print data=idlabel label noobs;
     title 'Student Test Scores';
  run;
Display the IDLABEL variable names and label. PROC CONTENTS displays the variable names and labels.
proc contents data=idlabel;
run;

Output 1

This data set is the output data set, IDLABEL.
Student Test Scores, IDLABEL
                             Student Test Scores                              1

 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

Program 2

proc contents data=idlabel;
run;

Program Description

Display the variable and label names. PROC CONTENTS will display the variable names and the labels used in the first program.
proc contents data=idlabel;
run;

Output 2

In the following output, PROC CONTENTS displays the variables and labels.
The Contents Procedure
Student Test Scores                                      2

                             The CONTENTS Procedure

                  Alphabetic List of Variables and Attributes

            #    Variable    Type    Len    Label

            1    Test        Char      8    NAME OF FORMER VARIABLE
            2    sn0545      Num       8    Capalleti
            8    sn0674      Num       8    McBane
            4    sn1167      Num       8    Engles
            5    sn1230      Num       8    Grant
            3    sn1252      Num       8    Dubose
            6    sn2527      Num       8    Krupski
            7    sn4860      Num       8    Lundsford