SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
rclivornese
Calcite | Level 5

Is there a way to get the stats used in vbox into a sas dataset for later usage?

 

This example was posted a few years ago, but it only shows how to get the statistics into the plot. 

 

proc sgplot data=want;
label weight_n='N' weight_min='MIN' weight_max='MAX'
weight_median='MEDIAN' weight_mean='MAEAN';
vbox weight/category=sex group=sex;
xaxistable weight_n weight_min weight_max weight_median weight_mean
/ x=sex colorgroup=sex location=inside;

 

Thanks!

3 REPLIES 3
Reeza
Super User
Probably but it would likely be in a format for plotting and not totally useful. You can easily get that from PROC MEANS or SUMMARY into a nicely formatted data set.

https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic.sas
rclivornese
Calcite | Level 5

That won't directly provide all the critical points for the box plot. (e.g. the ends of the whiskers are not the min/max of the whole data set). 

I think this will do it. Please let me know if you think this is accurate:

 

data have;
set sashelp.class;
run;

proc means data=have nway noprint;
class sex;
var weight;
output out=stat min= max= median= mean= p25= p75=
n=/autoname;
run;

data stat; set stat;
upgate=weight_p75+1.5*(weight_p75-weight_p25);
downgate=weight_p75-1.5*(weight_p75-weight_p25);
run;

proc sql;
create table have2 as
select a.*
from have a
INNER JOIN
stat b
on a.sex = b.sex
where a.weight between downgate and upgate
;
quit;

proc means data=have2 nway;
class sex;
var weight;
output out=out_wisk
min=wisk_min
max=wisk_max
n=/autoname;
run;

proc sql;
select a.sex,
b.wisk_min,
a.weight_p25,
a.weight_median,
a.weight_mean,
a.weight_p75,
b.wisk_max
from stat a
INNER JOIN
out_wisk b
on a.sex = b.sex
;
quit;

 

 

Reeza
Super User

Add this before your SGPLOT statement. You'll likely have to reformat it then.

 

ods output sgplot=want;

Found via this blog post.

 

Here's some instructions and explanations on how to capture output that is shown.
https://blogs.sas.com/content/sastraining/2017/03/31/capturing-output-from-any-procedure-with-an-ods...

 


@rclivornese wrote:

Is there a way to get the stats used in vbox into a sas dataset for later usage?

 

This example was posted a few years ago, but it only shows how to get the statistics into the plot. 

 

proc sgplot data=want;
label weight_n='N' weight_min='MIN' weight_max='MAX'
weight_median='MEDIAN' weight_mean='MAEAN';
vbox weight/category=sex group=sex;
xaxistable weight_n weight_min weight_max weight_median weight_mean
/ x=sex colorgroup=sex location=inside;

 

Thanks!


 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1406 views
  • 1 like
  • 2 in conversation