So I am working on generating summary dataset. I need to print only the values of N,MIN,MEDIAN,MAX,STD. It will be convenient for me to get the result as the statistics in a single variable stat. But if I use proc means without specifying the stats after output statement, I just get the default stats. Is there any way of doing this? This is what I tried.
PROC MEANS DATA=sashelp.class NWAY N MIN MAX MEDIAN STD;
CLASS name;
VAR height weight;
OUTPUT OUT=output (DROP=_type_ _freq_ RENAME=(_stat_=stat)) ;
RUN;
It only shows the default stats. Anyway, I can specify the stats in output option, but I want the output like from the code I have provided. Thanks in advance for helping.
No.
Generate them in "wide" format and then transpose to "tall" if you want.
PROC SUMMARY DATA=sashelp.class NWAY N MIN MAX MEDIAN STD;
CLASS name;
VAR height weight;
OUTPUT OUT=wide n= min= max= median= std= /autoname ;
RUN;
proc transpose data=wide(drop=_type_ _freq_) out=tall ;
by name ;
run;
data tall ;
set tall ;
length Stat $32 ;
stat = scan(_name_,-1,'_');
_name_=substr(_name_,1,length(_name_)-length(stat)-1);
run;
proc transpose data=tall out=want(drop=_name_);
by name stat notsorted;
id _name_;
var col1 ;
run;
Results:
Obs Name Stat Height Weight
1 Alfred N 1.0 1.0
2 Alfred Min 69.0 112.5
3 Alfred Max 69.0 112.5
4 Alfred Median 69.0 112.5
5 Alfred StdDev . .
6 Alice N 1.0 1.0
7 Alice Min 56.5 84.0
8 Alice Max 56.5 84.0
9 Alice Median 56.5 84.0
10 Alice StdDev . .
...