BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hinashah
Calcite | Level 5

I have an sgpanel where I want to show categorical boxplots inside each panel. For these boxplots, I'd like to display the mean quantity. However, I can't find a way to do this. Is it possible? Here's my proc sgpanel, and the result is below. I'd like to display the value for mean on this panel for each of the box. 

 

proc sgpanel data=new_one;
panelby testtrain;
vbox diff/category=category nooutliers group=category transparency=0.3;
refline 0/axis=Y lineattrs=(colors=black thickness=2);
run;

hinashah_0-1595703726855.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Mean quantity of what variable? Within group?

 

Here is an example that may help using the SASHELP.Class dataset that plots VBox of weight by age, paneled by sex.

Basically it involves calculating the mean of whatever and then overlaying a scatter plot to show the value.

proc sort data=sashelp.class
   out=work.class;
   by sex;
run;

proc summary data=work.class nway;
   class sex age;
   var weight;
   output out=work.summary(drop=_:) mean=meanweight;
run;

data work.plot;
   set work.class
       work.summary
   ;
run;

proc sgpanel data=work.plot;
   panelby sex;
   vbox weight /category=age group=age ;
   scatter x=age y=meanweight /markerchar=meanweight;
run;

Since the format associated with Meanweight by default is a BEST you may want to specify a format to display fewer decimals.

View solution in original post

2 REPLIES 2
ballardw
Super User

Mean quantity of what variable? Within group?

 

Here is an example that may help using the SASHELP.Class dataset that plots VBox of weight by age, paneled by sex.

Basically it involves calculating the mean of whatever and then overlaying a scatter plot to show the value.

proc sort data=sashelp.class
   out=work.class;
   by sex;
run;

proc summary data=work.class nway;
   class sex age;
   var weight;
   output out=work.summary(drop=_:) mean=meanweight;
run;

data work.plot;
   set work.class
       work.summary
   ;
run;

proc sgpanel data=work.plot;
   panelby sex;
   vbox weight /category=age group=age ;
   scatter x=age y=meanweight /markerchar=meanweight;
run;

Since the format associated with Meanweight by default is a BEST you may want to specify a format to display fewer decimals.

hinashah
Calcite | Level 5

Thanks for your reply! I used your suggestion, and changed my code to something like this. I did want the mean to be displayed for the variable diff. Used the datalabel for scatter, and also added a colaxistable.

proc summary data=new_one nway;
	class testtrain category;
	var diff;
	output out=new_summary(drop=_:) mean=meandiff;
run;

data for_panel;
	set new_one new_summary;
run;

proc sgpanel data=for_panel;
	panelby testtrain ;
	vbox diff/category=category nooutliers group=category datalabel ;
	scatter x=category y=meandiff / datalabel=meandiff markerattrs=(size=1px);
	rowaxis values= (0 to 150 by 7) grid label='difference';
	refline 0 / axis=Y lineattrs=(color=black thickness=1);
	colaxistable diff /X=category stat=mean label='mean' separator;
	title 'Difference from Ground Truth';
run;

Here's the result:

 

hinashah_1-1596210054905.png

Thanks for your suggestion!!

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1067 views
  • 1 like
  • 2 in conversation