I'm using proc summary to calculate some quintiles, and I'm trying to get it in an output so it's easier to copy and paste across.
proc summary data=example min q1 median q3 max print;
var variable_1 variable_2;
output out=example_quintiles;
run;
I ran that and get the results in the format I want printed
However I get something completely different in the output data, which makes it more difficult to copy and paste.
Any ideas?
Sadly, the default OUTPUT structure does not honor the statistics set in the PROC MEANS statement, so we need to beat the output into shape:
(using SASHELP.CLASS as an example)
proc summary data=sashelp.class min q1 median q3 max print;
var height weight;
output out=summary min= q1= median= q3= max= / autoname;
run;
proc transpose
data=summary
out=long1
;
var height: weight:;
run;
data long2;
set long1;
varname = scan(_name_,1,"_");
stat = scan(_name_,2,"_");
run;
proc transpose
data=long2
out=want (drop=_name_)
;
by varname;
var col1;
id stat;
run;
You can use ODS and the STACKODS PROC statement option to get this data directly.
ods select none;
proc summary data=sashelp.class min q1 median q3 max print stackods;
var height weight;
ods output summary=summary;
run;
ods select all;
proc print data=summary;
run;
@Kurt_Bremser wrote:
Sadly, the default OUTPUT structure does not honor the statistics set in the PROC MEANS statement, so we need to beat the output into shape:
(using SASHELP.CLASS as an example)
proc summary data=sashelp.class min q1 median q3 max print; var height weight; output out=summary min= q1= median= q3= max= / autoname; run; proc transpose data=summary out=long1 ; var height: weight:; run; data long2; set long1; varname = scan(_name_,1,"_"); stat = scan(_name_,2,"_"); run; proc transpose data=long2 out=want (drop=_name_) ; by varname; var col1; id stat; run;
Copy and Paste what?
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.