Expanding on Linlin's ideas and assuming SAS version 9.1 and no SAS/Access to PC Files:
proc means data = sashelp.class noprint;
var age ;
OUTPUT OUT=dat1 (drop=_:) q1=q1 q3=q3 qrange=qrange ;
run;
proc means data = sashelp.class noprint;
var height ;
OUTPUT OUT=dat2 (drop=_:) q1=q1 q3=q3 qrange=qrange ;
run;
proc means data = sashelp.class noprint;
var weight ;
OUTPUT OUT=dat3 (drop=_:) q1=q1 q3=q3 qrange=qrange ;
run;
data want;
length item $ 10;
set dat1;
item="age";
output;
set dat2;
item="height";
output;
set dat3;
item="weight";
output;
run;
proc print;run;
*output:
Obs item q1 q3 qrange
1 age 12.0 15.0 3
2 height 57.5 66.5 9
3 weight 84.0 112.5 28.5
;
*old fashion CSV output to flat file;
filename csv "C:\temp\Quartiles.csv";
data _null_;
set want;
file csv;
if _n_=1 then
put @1 "Variable,"
@12 "q1,"
@22 "q3,"
@32 "qrange"
;
put @1 item ","
@12 q1 best8. ","
@22 q3 best8. ","
@32 qrange best8.
;
run;
hi ... rather than use a data step to assemble the data after MEANS, how about using a data step prior to SUMMARY and running it once ...
data class (keep=variable value) / view=class;
set sashelp.class;
array nm(*) _numeric_;
do j=1 to dim(nm);
variable = vname(nm(j));
value = nm(j);
output;
end;
run;
proc summary data=class nway;
class variable;
var value;
output out=stats (drop=_:) q1=q1 q3=q3 qrange=qrange;
run;
variable q1 q3 qrange
Age 12.0 15.0 3.0
Height 57.5 66.5 9.0
Weight 84.0 112.5 28.5
* create CSV file without ACCESS to PC Files module;
ods csv file='z:\stats.csv';
proc print data=stats noobs;
run;
ods csv close;
Thank you, MIke. I really like your solution. My mind is still in the mainframe and flat file mode.
I ended up geting sas 9.3 so I was able to use the stackods option, thank you all for the help.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.