If you have SAS 9.3 or newer, and are using ODS OUTPUT
, you can do this with the STACKODSOUTPUT
option.
ods output summary=test ;
proc summary data=sashelp.class print mean p5 p95 stackodsoutput;
class sex;
var height weight;
run;
ods output close;
If you are doing it via the output
statement in the PROC, or have SAS 9.2 or earlier, you will have to postprocess the data to transpose it. If you used /AUTONAME
, you can do so fairly easily.
proc summary data=sashelp.class print mean p5 p95 stackodsoutput;
class sex;
var height weight;
output out=test mean= p5= p95= /autoname;
run;
data test2;
set test;
array vars height: weight:;
do _t = 1 to dim(vars);
varname = scan(vname(vars[_t]),1,'_'); *this would be more complex if you have _ in your variable names;
statistic = scan(vname(vars[_t]),-1,'_'); *this would be okay, though;
value = vars[_t];
output;
end;
keep sex varname statistic value;
run;
proc transpose data=test2 out=test3(drop=_name_);
by sex varname;
id statistic;
var value;
run;