The TRANSPOSE Procedure |
Restriction: | Do not use PROC TRANSPOSE with a BY statement or an ID statement if another user is updating the data set at the same time. |
Main discussion: | BY |
Featured in: | Transposing BY Groups |
BY <DESCENDING> variable-1
<...<DESCENDING> variable-n> <NOTSORTED>; |
Required Arguments |
specifies the variable that PROC TRANSPOSE uses to form BY groups. You can specify more than one variable. If you do not use the NOTSORTED option in the BY statement, then either the observations must be sorted by all the variables that you specify, or they must be indexed appropriately. Variables in a BY statement are called BY variables.
Options |
specifies that the data set is sorted in descending order by the variable that immediately follows the word DESCENDING in the BY statement.
specifies that observations are not necessarily sorted in alphabetic or numeric order. The data is grouped in another way, such as chronological order.
The requirement for ordering or indexing observations according to the values of BY variables is suspended for BY-group processing when you use the NOTSORTED option. The procedure does not use an index if you specify NOTSORTED. The procedure defines a BY group as a set of contiguous observations that have the same values for all BY variables. If observations with the same values for the BY variables are not contiguous, then the procedure treats each contiguous set as a separate BY group.
The NOBYSORTED system option disables observation sequence checking system-wide and applies to all procedures and BY statements. See the BYSORTED system option in the SAS Language Reference: Dictionary.
Transpositions with BY Groups |
PROC TRANSPOSE does not transpose BY groups. Instead, for each BY group, PROC TRANSPOSE creates one observation for each variable that it transposes.
The following figure shows what happens when you transpose a data set with BY groups. TYPE is the BY variable, and SOLD, NOTSOLD, REPAIRED, and JUNKED are the variables to transpose.
The number of observations in the output data set (12) is the number of BY groups (3) multiplied by the number of variables that are transposed (4).
The BY variable is not transposed.
_NAME_ contains the name of the variable in the input data set that was transposed to create the current observation in the output data set. You can use the NAME= option to specify another name for the _NAME_ variable.
The maximum number of observations in any BY group in the input data set is two; therefore, the output data set contains two variables, COL1 and COL2. COL1 and COL2 contain the values of SOLD, NOTSOLD, REPAIRED, and JUNKED.
Note: If a BY group in the input data set has more observations than other BY groups, then PROC TRANSPOSE assigns missing values in the output data set to the variables that have no corresponding input observations.
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.