Chapter Contents


The TRANSPOSE Procedure

Example 4: Transposing BY Groups

Procedure features:
BY statement
VAR statement
Other features: Data set option:

This example illustrates transposing BY groups and selecting variables to transpose.


options nodate pageno=1 linesize=80 pagesize=40;
 Note about code
data fishdata;
   infile datalines missover;
   input Location & $10. Date date7.
         Length1 Weight1 Length2 Weight2 Length3 Weight3
         Length4 Weight4;
   format date date7.;
Cole Pond   2JUN95 31 .25 32 .3  32 .25 33 .3
Cole Pond   3JUL95 33 .32 34 .41 37 .48 32 .28
Cole Pond   4AUG95 29 .23 30 .25 34 .47 32 .3
Eagle Lake  2JUN95 32 .35 32 .25 33 .30
Eagle Lake  3JUL95 30 .20 36 .45
Eagle Lake  4AUG95 33 .30 33 .28 34 .42
 Note about code
proc transpose data=fishdata
 Note about code
   var length1-length4;
 Note about code
   by location date;

 Note about code
proc print data=fishlength noobs;
   title 'Fish Length Data for Each Location and Date';

The output data set, FISHLENGTH. For each BY group in the original data set, PROC TRANSPOSE creates four observations, one for each variable it is transposing. Missing values appear for the variable Measurement (renamed from COL1) when the variables being transposed have no value in the input data set for that BY group. Several observations have a missing value for Measurement. For example, in the last observation, a missing value appears because there was no value for Length4 on 04AUG95 at Eagle Lake in the input data. [HTML Output]
 [Listing Output]

Chapter Contents



Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.