As the first step in the decommissioning of the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

Now You Can Annotate Your Statistical Graphics Procedure Graphs

From sasCommunity
Jump to: navigation, search


Have you ever had a situation where you wanted to add custom labeling or other graphical features to your statistical graphics (SG) procedure output but could not find a way to do it? Even with all of the plot types and options of the SG procedures, you might have run into this situation. With SAS® 9.3, you can add these features directly by using the new annotation support in the SG procedures.

The annotation data set definition used by these procedures has been redesigned to take advantage of ODS Graphics functionality. This paper will discuss this functionality in detail, highlighting new features in this system that include the following:

  • rich text support (including superscripts, subscripts, and Unicode)
  • transparency support for all primitives
  • more drawing spaces for easier placement of annotations


Oval Example 1: Creating a Bubble Legend

This example uses the new bubble plot that is added to the SG procedures in SAS 9.3. The bubble labels reflect the Y axis value by default (the data label variable can be assigned), but you might also want a legend showing the values for bubble sizes. You can make a bubble legend using annotate.

The key to making the legend sizes synchronize with the plot is using the BRADIUSMIN and BRADIUSMAX options in the BUBBLE statement of the procedure. You can use these options to set the minimum and maximum size of the bubbles. You then use those sizes to create the bubbles in the legend for the minimum and maximum data values.


 data anno; 
   retain drawspace "wallpercent" widthunit "pixel" heightunit "pixel" linethickness 1 textsize 8; 
   length function $ 9; 
   input function $ x1 y1 width height x2 y2 textsize anchor $ label $ 48-66 display $ 68-74 fillcolor $ 76-80; 
   Rectangle 86 76.5 140 87  .    . 12 bottom                     all     white 
   Oval      80 76.5  44 44  .    . 12 bottom                     outline 
   Oval      80 76.5  16 16  .    . 12 bottom                     outline 
   Line      80 87.9   .  . 87 87.9 12 bottom 
   Line      80 80.5   .  . 87 80.5 12 bottom 
   Text      86 98   140  .  .    . 12 top    Salary (in dollars)
   Text      87 88.1 140  .  .    .  8 left   $32,816 
   Text      87 80.4 140  .  .    .  8 left   $18,444 
 Title1 "Survey of Engineering Jobs"; 
 proc sgplot data=jobs sganno=anno; 
   yaxis grid; 
   bubble y=Num x=Eng size=Dollars / datalabel bradiusmax=22px bradiusmin=8px; 

Notice that the grid line does not go through the bubble legend. The DISPLAY column sets both the fill and the outline to be enabled. The FILLCOLOR column is set to be white so that anything behind the legend is hidden. The DISPLAY value is set back to outline for the ovals.

Online Materials

View the PDF of the paper.

Contact Info

If you have any questions, here is my contact information.