SUPPORT / SAMPLES & SAS NOTES
 

Support

Sample 44637: Double PROC TRANSPOSE method for reshaping your data set with multiple BY variables

DetailsCodeAboutRate It
You might have the need to reshape your data set to get one unique row for each unique value of a BY variable. When a second BY variable is involved, you can use a double PROC TRANSPOSE method to reshape your data set. For example, you might have data that is structured like the following:
myID  time    s1    s2    s3

 1     T1     85    85    86
 1     T2     80    79    70
 1     T3     78    77    87
 2     T1     79    79    79
 2     T2     83    83    85
You want the resulting data set to have one unique record for each value of MyID, like this:
 
myID  s1_T1   s2_T1   s3_T1   s1_T2   s2_T2   s3_T2   s1_T3   s2_T3   s3_T3

 1     85      85      86      80      79      70      78      77      87
 2     79      79      79      83      83      85       .       .       .

To obtain this result, you can use a double PROC TRANSPOSE method like the one shown on the Full Code tab. Note that prior to SAS® 9.2, an interim DATA step is required before the second PROC TRANSPOSE step.


These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.