Data visualization with SAS programming

Simple Annotation on Proc Boxplot

Accepted Solution Solved
Reply
Contributor
Posts: 26
Accepted Solution

Simple Annotation on Proc Boxplot

Please offer me your assistance O' great internet SAS lords. My ultimate goal is to annotate the number of observations by group on a box plot. However, I am stuck for I can not even get a simple annotation to appear on my plot! My code is below along with the outputted plot.

 

data testplot;
 do i=1 to 10;
  grp=i;
  time=5; 
  output;
 end;
run;

data test_anno;
 length function $8;
 retain xsys ysys "2" hsys "3" function "label" size 1;
 x=5; y=5; text="testing";output;
 run;

proc boxplot data=testplot;
plot time*grp/horizontal annotate=test_anno;
run;

tempgraph.png


Accepted Solutions
Solution
‎02-10-2017 02:54 PM
Contributor
Posts: 35

Re: Simple Annotation on Proc Boxplot

Hi.

 

In

SAS/STAT® 13.1 User’s Guide

The BOXPLOT Procedure

it suggests that annotate won't work if ODS graphics is enabled.

 

I just tried adding

ODS graphics off;

 

before your code, and the annotate seemed to work. 

(and the plot was horizontal).

 

Hope that helps.

 

View solution in original post


All Replies
SAS Employee
Posts: 118

Re: Simple Annotation on Proc Boxplot

Hi,

 

I don't have a solution for you but I can see the annotate seems to be incomplete.

I found 2 samples for you from Robert Allison's SAS/Graph Examples! page where the Boxplot procedure is used with an annotate:

  http://robslink.com/SAS/democd29/mpgplot.sas

  http://robslink.com/SAS/democd22/tele_gif.sas

 

Hope that helps you.

 

Cheers,

Damo

SAS Super FREQ
Posts: 1,171

Re: Simple Annotation on Proc Boxplot

[ Edited ]

Customizing BoxPlots is a lot easier with SGPLOT procedure.  There are many examples in Graphically Speaking blog.  Here is one of Box with added Stat Table.  Annotation may not be required based on the release level of SAS you have.  

Contributor
Posts: 26

Re: Simple Annotation on Proc Boxplot

[ Edited ]
Posted in reply to Sanjay_SAS

Thanks! Doesn't solve my original question but sure does solve my overall problem. Haha... linking back to your own article I see. How ingenious of you. The code below adds the number of observations next to each group. Oh and if you were like me and the graph failed to output due to the maximum allotted space for JAVA, you can increase the space by editing the SAS config file. More specifically, changing  -xmx128m and -xms128m to a higher number. 

 

ods output sgplot=sgplotdata;
proc sgplot data=testplot;
hbox time/category=grp;
run;

data sdata;
set sgplotdata;
where BOX_TIME_X_GRP_SORTORDER_Inte__Y ne . and
BOX_TIME_X_GRP_SORTORDER_Inte_ST = 'N';
rename BOX_TIME_X_GRP_SORTORDER_Inte_ST=stat BOX_TIME_X_GRP_SORTORDER_Inte__Y=value BOX_TIME_X_GRP_SORTORDER_Inte__X=cat;
keep BOX_TIME_X_GRP_SORTORDER_Inte_ST BOX_TIME_X_GRP_SORTORDER_Inte__Y BOX_TIME_X_GRP_SORTORDER_Inte__X;
run;

data merged;
set testplot sdata;
run;

proc sgplot data=merged;
hbox time/category=grp;
yaxistable value/y=cat class=stat;
run;

tempgraph.png

Super User
Posts: 11,343

Re: Simple Annotation on Proc Boxplot


pkfamily wrote:

Please offer me your assistance O' great internet SAS lords. My ultimate goal is to annotate the number of observations by group on a box plot. However, I am stuck for I can not even get a simple annotation to appear on my plot! My code is below along with the outputted plot.

 

data testplot;
 do i=1 to 10;
  grp=i;
  time=5; 
  output;
 end;
run;

data test_anno;
 length function $8;
 retain xsys ysys "2" hsys "3" function "label" size 1;
 x=5; y=5; text="testing";output;
 run;

proc boxplot data=testplot;
plot time*grp/horizontal annotate=test_anno;
run;

 


Most likely the issue is that the annotate data set does not have a WHEN variable. When controls whether the annotate data is applied before (When='B' and is the default [which I have never quite figured out the rationale for] ) or after the graph (When='A'). When drawn before then the boxplot output covers the annotation.

Add When='A'; to the annotate data set and see if that fixes the Proc Boxplot issue.

 

 

Contributor
Posts: 26

Re: Simple Annotation on Proc Boxplot

Thank you so much for offering your advice! Still no good however. Here is the code I used along with printed annotate dataset.

 

data test_anno;
 length function $8;
 retain xsys ysys "2" hsys "3" function "label" size 1;
 When='A';
 x=5; y=5; text="testing";output;
 run;

 

tempgraph.png

 
Super User
Posts: 11,343

Re: Simple Annotation on Proc Boxplot

You don't have a unit with SIZE so defaulting to the html output it could be very small. So try SIZE=3 or 4.

 

Post your current GOPTIONS as well.

 

With:

data test_anno;
 length function $8;
 retain xsys ysys "2" hsys "3" function "label" size 5;
 x=5; y=5; when='A'; text="testing";output;
 run;

proc boxplot data=testplot;
plot time*grp/horizontal annotate=test_anno;
run;

boxplot5.png

 

 

Contributor
Posts: 26

Re: Simple Annotation on Proc Boxplot

Hmm... Size=5; didn't change anything. How do I post my goptions? I ran proc goptions;run; and lots of text was outputted into my log. I wouldn't dare post all that here.

Solution
‎02-10-2017 02:54 PM
Contributor
Posts: 35

Re: Simple Annotation on Proc Boxplot

Hi.

 

In

SAS/STAT® 13.1 User’s Guide

The BOXPLOT Procedure

it suggests that annotate won't work if ODS graphics is enabled.

 

I just tried adding

ODS graphics off;

 

before your code, and the annotate seemed to work. 

(and the plot was horizontal).

 

Hope that helps.

 

Contributor
Posts: 26

Re: Simple Annotation on Proc Boxplot

Posted in reply to ABritinAus
Perfecto! You are the best. I really need to learn how to dig through SAS Documentation
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 407 views
  • 3 likes
  • 5 in conversation