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

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

1 ACCEPTED SOLUTION

Accepted Solutions
ABritinAus
Obsidian | Level 7

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

9 REPLIES 9
Damo
SAS Employee

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

Jay54
Meteorite | Level 14

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.  

pkfamily
Obsidian | Level 7

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

ballardw
Super User

@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.

 

 

pkfamily
Obsidian | Level 7

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

 
ballardw
Super User

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

 

 

pkfamily
Obsidian | Level 7

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.

ABritinAus
Obsidian | Level 7

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.

 

pkfamily
Obsidian | Level 7
Perfecto! You are the best. I really need to learn how to dig through SAS Documentation

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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