Example Program and Statement Details

Example Graph

The following graph was generated by the Example Program. The example uses DRAWRECTANGLE to highlight a student’s data point. It draws a rectangle around the marker symbol that represents the student’s height and weight, and it displays the student’s name inside of the rectangle. In the BEGINGRAPH statement, the setting for the DRAWSPACE= option sets the drawing space and drawing units for the DRAWRECTANGLE and DRAWTEXT statements. In the DRAWRECTANGLE statement, setting TRANSPARENCY=0.75 ensures that the marker for Alfred is visible behind the rectangle. The DRAWTEXT statement draws the text that identifies the student's name, using the ANCHOR=, X=, and Y= options to position the text within the rectangle.
Drawing a Rectangle in a Graph

Example Program

proc template;
  define statgraph drawrectangle;
    begingraph / drawspace=datavalue;
      entrytitle "Regression Fit Plot";
      layout overlay;
        modelband "myclm";
        scatterplot x=height y=weight;
        regressionplot x=height y=weight / alpha=.01 clm="myclm";
          drawrectangle x=69 y=112.5 width=10 height=15 /
            display=all fillattrs=(color=green)
            transparency=0.75 ;
          drawtext "Alfred" / x=69 y=112 anchor=top;
      endlayout;
    endgraph;
  end;

proc sgrender data=sashelp.class template=drawrectangle;
run;

Statement Summary

A DRAWRECTANGLE statement draws a rectangle in a graph. The rectangle position is determined by the X and Y anchor points, and the size is determined by the HEIGHT and WIDTH settings. You can manage the rectangle position with the options ANCHOR=, XSPACE=, and YSPACE=. You can manage the rectangle size with the HEIGHTUNIT= and WIDTHUNIT= options.
For general information about the types of elements that can be drawn with the draw statements, the drawing space and drawing units that they use, and how the drawn elements are anchored, see Key Concepts for Using Draw Statements. For detailed usage information, consult the SAS Graph Template Language: User's Guide.

Required Argument

X=constant | scalar-expression
specifies the X value of the anchor point.
Interaction: The value that is set for this argument is interpreted using the XSPACE= option. When XSPACE=DATAVALUE, the value is interpreted using the XAXIS= option.
Y=constant | scalar-expression
specifies the Y value of the anchor point.
Interaction: The value that is set for this argument is interpreted using the YSPACE= option. When YSPACE=DATAVALUE, the value is interpreted using the YAXIS= option.
WIDTH=constant | scalar-expression
specifies the width of the rectangle.
Interaction: The value that is set for this argument is interpreted using the WIDTHUNIT= and XSPACE= options. When WIDTHUNIT=DATA, the value is interpreted using the XAXIS= option.
HEIGHT=constant | scalar-expression
specifies the height of the rectangle.
Interaction: The value that is set for this argument is interpreted using the HEIGHTUNIT= and YSPACE= options. When HEIGHTUNIT=DATA, the value is interpreted using the YAXIS= option.

Options

Statement Option
Description
Specifies an anchor point for the rectangle.
Specifies the radius of the rectangle corners.
Specifies an amount to offset the anchor point from discrete X values, or discrete Y values, or both.
Specifies the features to display for the rectangle.
Specifies a default drawing space and drawing units for this DRAWRECTANGLE statement.
Specifies the appearance of the rectangle’s filled area.
Specifies whether the value that is specified for the rectangle’s HEIGHT is interpreted as a percentage value, a pixel value, or a value that is in the units of the data.
Specifies whether the rectangle appears on top of or behind the graph.
Specifies the properties of the outline that is drawn around the rectangle.
Specifies the degree of the transparency of the fill and the outline.
Specifies whether the value that is specified for the rectangle’s WIDTH is interpreted as a percentage value, a pixel value, or a value that is in the units of the data.
Specifies whether the value that is specified for the rectangle’s X anchor point is interpreted using the primary X axis scale or to the secondary X (X2) axis scale.
Specifies the drawing space and drawing units for interpreting the value that is specified for the rectangle’s X anchor point.
Specifies whether the value that is specified for the rectangle’s Y anchor point is interpreted using the primary Y axis scale or to the secondary Y (Y2) axis scale.
Specifies the drawing space and drawing units for interpreting the value that is specified for the rectangle’s Y anchor point.
ANCHOR=CENTER | TOPLEFT | TOP | TOPRIGHT | LEFT | RIGHT | BOTTOMLEFT | BOTTOM | BOTTOMRIGHT
specifies an anchor point for the rectangle.
Default: CENTER
Discussion: The anchor point can be at the center of the rectangle or at eight points on the rectangle border. The following figure shows the anchor points for TOPLEFT and CENTER.
rectangle anchor positions
The coordinates of the anchor point are set by the statement’s X and Y values, and by the settings for the XSPACE= and YSPACE= options. The XAXIS= and YAXIS= option might affect positioning when the XSPACE= or YSPACE= options are set to DATAPIXEL, DATAPERCENT, or DATAVALUE.
CORNERRADIUS=number
specifies the radius of the rectangle corners.
Note: This feature is for the second maintenance release of SAS 9.3 and later. See What's New in the SAS 9.3 Graph Template Language.
Default: 0
Range: 0 (square corners) to 1 (most rounded corners)
DISCRETEOFFSET= number
specifies an amount to offset the anchor point from discrete X values, or discrete Y values, or both.
Default: 0 (no offset, the anchor point is centered on discrete X values, or discrete Y values, or both)
Range: -0.5 to +0.5, where .5 represents half the distance between discrete ticks. If the X axis is discrete, a positive offset is to the right. If the Y axis is discrete, a positive offset is up. If REVERSE=TRUE on the X or Y axis, then the offset direction is also reversed.
DISPLAY=STANDARD | ALL | (display-options)
specifies the features to display for the rectangle.
Default: STANDARD
STANDARD
displays an outlined rectangle.
ALL
displays an outlined, filled rectangle.
(display-options)
a list of options, enclosed in parentheses, that must include one of the following:
OUTLINE displays an outlined rectangle
FILL displays a filled rectangle
Tip: Use the OUTLINEATTRS= and FILLATTRS= options to control the appearance of the rectangle.
DRAWSPACE= GRAPHPERCENT | GRAPHPIXEL | LAYOUTPERCENT | LAYOUTPIXEL | WALLPERCENT | WALLPIXEL | DATAPERCENT | DATAPIXEL | DATAVALUE
specifies a default drawing space and drawing units for this DRAWRECTANGLE statement.
Default: LAYOUTPERCENT
Interaction: This statement and all of the draw statements inherit the global DRAWPSACE= setting from the DRAWSPACE= option in the BEGINGRAPH statement. Setting this option changes the setting for only this DRAWRECTANGLE statement.
Interaction: This option sets the default drawing space, but individual settings in the X or Y dimension can be overridden by the options XSPACE=, YSPACE=, HEIGHTUNIT =, or WIDTHUNIT=.
FILLATTRS=style-element | style-element (fill-options) | (fill-options)
specifies the appearance of the fill. See General Syntax for Attribute Options for the syntax on using a style-element and Fill Options for available fill-options.
Default: The GraphAnnoShape style element
Tip: The TRANSPARENCY= option sets the transparency for the fill and the outline. You can combine this option with TRANSPARENCY= to set one transparency for the outline but a different transparency for the fill. Example:
transparency=0.2 fillattrs=(transparency=0.6)
HEIGHTUNIT=PERCENT | PIXEL | DATA
specifies whether the value that is specified for the rectangle’s HEIGHT is interpreted as a percentage value, a pixel value, or a value that is in the units of the data.
Default: PERCENT
Interaction: This setting combines with the YSPACE= setting to interpret the height that is set in the HEIGHT= argument.
LAYER=FRONT | BACK
specifies whether the rectangle appears on top of (FRONT) or behind (BACK) the graph.
Default: FRONT
Interaction: If this option is set to BACK, the rectangle is drawn behind background areas, such as a layout or legend background.For elements that are obstructed because they are in the back layer, you can suppress the display of filled areas in the graph. Or, you can use transparency to manage the element visibility. For more information, see About Drawing Layers.
OUTLINEATTRS= style-element | style-element (line-options) | (line-options)
specifies the properties of the outline that is drawn around the rectangle. See General Syntax for Attribute Options for the syntax on using a style-element and Line Options for available line-options.
Default: The GraphAnnoShape style element.
Interaction: For this option to have any effect, the outline must be enabled by the DISPLAY= option or by the ODS style that is in effect.
TRANSPARENCY= number
specifies the degree of the transparency of the fill and the outline.
Default: 0
Range: 0 (opaque) to 1 (entirely transparent)
Tip: The FILLATTRS= option can be used to set transparency for just the fill. You can combine this option with FILLATTRS= to set one transparency for the outline but a different transparency for the fill. Example:
transparency=0.2 fillattrs=(transparency=0.6)
WIDTHUNIT=PERCENT | PIXEL | DATA
specifies whether the value that is specified for the rectangle’s WIDTH is interpreted as a percentage value, a pixel value, or a value that is in the units of the data.
Default: PERCENT
Interaction: This setting combines with the XSPACE= setting to interpret the width that is set in the WIDTH= argument.
XAXIS= X | X2
specifies whether the value that is specified for the rectangle’s X anchor point is interpreted using the primary X axis scale or to the secondary X (X2) axis scale.
Default: X
Interaction: This option has effect only if XSPACE=DATAVALUE.
XSPACE= GRAPHPERCENT | GRAPHPIXEL | LAYOUTPERCENT | LAYOUTPIXEL | WALLPERCENT | WALLPIXEL | DATAPERCENT | DATAPIXEL | DATAVALUE
specifies the drawing space and drawing units for interpreting the value that is specified for the rectangle’s X anchor point.
Default: The setting that is in effect for the DRAWSPACE= option.
YAXIS= Y | Y2
specifies whether the value that is specified for the rectangle’s Y anchor point is interpreted using the primary Y axis scale or to the secondary Y (Y2) axis scale.
Default: Y
Interaction: This option has effect only if YSPACE=DATAVALUE.
YSPACE= GRAPHPERCENT | GRAPHPIXEL | LAYOUTPERCENT | LAYOUTPIXEL | WALLPERCENT | WALLPIXEL | DATAPERCENT | DATAPIXEL | DATAVALUE
specifies the drawing space and drawing units for interpreting the value that is specified for the rectangle’s Y anchor point.
Default: The setting that is in effect for the DRAWSPACE= option.