SUPPORT / SAMPLES & SAS NOTES
 

Support

Usage Note 22932: How to use PROC TRANSPOSE to get one record per BY group

DetailsAboutRate It

Because of the structure of a data set, using the BY statement does not always guarantee that PROC TRANSPOSE will create an output data set containing one record per BY group. In some cases, it is necessary to use a BY variable that is unique for every record (if one does not already exist in the data set, use _N_), and then transpose the data set a second time. For example:

data test;
   n=_n_;
   input x y z;
   datalines;
1 2 3
1 2 3
2 3 4
3 4 5
3 4 5
4 4 5
;
run;

/* In order to keep the implied ID variable _NAME_ */
/* from causing errors in the second transpose,    */
/* eliminate it using the DROP= data set option    */
proc transpose out=first(drop=_name_);
   by n x;
   var y z;
run;

proc print; run;

proc transpose data=first out=second prefix=a;
   by x;
   var col1;
run;

proc print; 
run;


Operating System and Release Information

Product FamilyProductSystemSAS Release
ReportedFixed*
SAS SystemBase SASAlln/a
* For software releases that are not yet generally available, the Fixed Release is the software release in which the problem is planned to be fixed.