Assuming you are using the output option in proc means (and not ODS OUTPUT), you can control what comes in that dataset like so:
proc means data=sashelp.class;
var age;
class sex;
output out=mymeans nmiss= P1= P5= /autoname;
run;
The full list of statistic names is available in the PROC MEANS documentation under "statistics keyword".
You can also achieve the same result (with a slightly different output format) with ODS OUTPUT.
ods output summary=mymeans;
ods trace on;
proc means data=sashelp.class nmiss p1 p5;
var age;
class sex;
run;
ods trace off;
ods output close;
ODS TRACE on/off is to show the name of the table created (ie, 'summary'). It's not needed in production. In this case you ask for statistics the same way you ask for them to the output window (in the PROC MEANS statement).
Based on your edits, you want it transposed (one row per statistic). You can't get that directly, but the transposition isn't very hard.
proc means data=sashelp.class nmiss p1 p5;
class sex;
var _numeric_;
output out=mymeans n= mean= nmiss= p1= p5= /autoname ;
run;
data mymeans_out;
set mymeans(drop=_type_ _freq_);
by sex;
array numvars _numeric_;
format var stat $32.;
do _t = 1 to dim(numvars);
var=scan(vname(numvars[_t]),1,'_');
stat=scan(vname(numvars[_t]),-1,'_');
value = numvars[_t];
output;
end;
keep sex var stat value;
run;
This has a few limitations. If your variable names have underscores in them already, the var=scan...
line will need to be rewritten to use substr and find the last underscore, then var = substr(vname(...),1,position_of_last_underscore)
. Stat should be fine since it uses -1 (reverse direction). If your variable names might exceed ~23 characters, you may not get the exact variable name back out again as it may be truncated or modified. If that's the case, then the ODS OUTPUT solution from above will help you (as it provides in an additional column the name of the original variable), but some more work would be needed to relate that value to the truncated name.
I also drop _TYPE_
and _FREQ_
, to simplify the array definition; if you need those, then you'd need to write a bit of code to exclude them from separately being output, and keep them.