1
votes

Right now when I run a proc summary, the output dataset looks as follows:

VAR1 Label Mean VAR2 Label Mean

but I want the following format:

VAR1 Label Mean 
VAR2 Label Mean

How do I do this from my proc summary statement:

proc summarydata = full MEAN STD MEDIAN MIN MAX MEDIAN Q1 Q3 P95 P90 P5 print;
var X;
run; 
1
I edited the title some to make it more useful for searching.Joe

1 Answers

1
votes

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;