Example Program and Statement Details

Example Graph

The following graph was generated by the Example Program:
Example Graph with a Global Legend

Example Program

proc template;
  define statgraph globallegend;
    begingraph;
      entrytitle "Prediction Ellipses";
      layout overlay;
        scatterplot x=petallength y=petalwidth / group=species name="sp";
        ellipse x=petallength y=petalwidth / type=predicted alpha=.2
          name="p80" legendlabel="80%" outlineattrs=graphconfidence;
        ellipse x=petallength y=petalwidth / type=predicted alpha=.05
          name="p95" legendlabel="95%" outlineattrs=graphconfidence2; 
      endlayout;
      layout globalLegend / type=column title="Sample Global Legend";
        discretelegend "sp" / title="Species:";
        discretelegend "p80" "p95" / title="Predictions:";
      endLayout;
    endgraph;
  end;
run;

proc sgrender data=sashelp.iris template=globallegend; 
run;

Statement Summary

A global legend layout can contain multiple discrete or merged legends. Continuous legends are not supported inside the global legend block.
A global legend is placed at the bottom of the graph, just above the footnote(s). All of the discrete or merged legend statements that are nested within the global legend block are arranged into a single row or column, depending on the setting for the TYPE= option.
Depending on the outermost layout type and the legend content, the legend is centered on the graph wall area or on the graph output area. For example, if the outermost layout is an overlay layout, when positioning the legend, the GLOBALLEGEND statement first attempts to center the legend on the graph wall area. If that position causes the legend to be clipped, it then attempts to center the legend on the entire output area instead. In that case, the legend might appear to be slightly off-center with respect to the graph.
Only one global legend block is permitted in a graph. The block must be located within the BEGINGRAPH block, but outside of the outermost layout block.
When a global legend block is used, only legend statements within the block are displayed in the graph. Any legend statements that are specified outside of the global legend block are ignored.

Options

Statement Option
Description
Specifies whether a border is drawn around the legend.
Specifies the properties of the border line around the legend.
Specifies whether the global legend is displayed when any portion of its nested legends cannot be fully rendered because of space constraints.
Specifies the gap between nested legends.
Specifies the legend’s horizontal alignment within the graph area that is defined by the BEGINGRAPH block.
Specifies the position of each nested legend’s title.
Specifies the amount of extra space that is added inside the legend border.
Specifies a title for the global legend.
Specifies the color and font attributes of the global legend title.
Specifies whether nested legends are arranged into a single row or column.
Specifies the preferred space allocation for the nested legends.
BORDER=boolean
specifies whether a border is drawn around the legend.
Default: TRUE
Interaction: If this option is set to FALSE, the BORDERATTRS= option is ignored.
BORDERATTRS=style-element | style-element (line-options) | (line-options)
specifies the attributes of the border line around the legend. See General Syntax for Attribute Options for the syntax on using a style-element and Line Options for available line-options.
Default: The GraphBorderLines style element.
Interaction: BORDER=TRUE must be set for this option to have any effect.
DISPLAYCLIPPED= boolean
specifies whether the global legend is displayed when any portion of its nested legends cannot be fully rendered because of space constraints.
Default: FALSE.
Interaction: This option overrides any DISPLAYCLIPPED option that is set on its nested legend statements.
Details: When the graph size is reduced, parts of a nested legend (title, legend symbol, or legend value) might be clipped (truncated). When clipping occurs and this option is FALSE, the entire global legend is removed from the graph and the space for it is reclaimed by the remainder of the graph. When this option is TRUE, the global legend always appears, even if some parts of the nested legends have been clipped.
GUTTER= dimension
specifies the gap between nested legends.
Default: 0
HALIGN=CENTER | LEFT | RIGHT
specifies the legend’s horizontal alignment within the graph area that is defined by the BEGINGRAPH block.
Default: CENTER
Tip: When CENTER is in effect and the outermost layout is an overlay-type layout, the global legend is centered below the wall area if it can fit within the wall width.
LEGENDTITLEPOSITION= LEFT | TOP
specifies the position of each nested legend’s title. Specifying LEFT places each title to the left of the legend items for that legend. Specifying TOP places each title above the legend items for that legend.
Default: LEFT
PAD=dimension | (pad-options)
specifies the amount of extra space that is added inside the legend border.
Default: The default padding for all sides is 0. Values without units are in pixels (px). A unit must be provided if other than pixels.
dimension
Specifies a dimension to use for the extra space at the left, right, top, and bottom of the legend border.
(pad-options)
Enables separate settings for the left, right, top, and bottom padding dimensions. Use pad-options to create non-uniform padding. These options must be enclosed in parentheses. Each option is specified as a name = value pair. Sides not assigned padding are padded with the default amount.
Values without units are in pixels (px). A unit must be provided if other than pixels.
LEFT=dimension specifies the amount of extra space added to the left side.
RIGHT=dimension specifies the amount of extra space added to the right side.
TOP=dimension specifies the amount of extra space added to the top.
BOTTOM=dimension specifies the amount of extra space added to the bottom.
TITLE= “string
specifies a title for the global legend.
Default: no title is displayed for the global legend
Restriction: The string must be enclosed in quotation marks.
Tip: The title for the global legend is independent of the titles for its nested legends.
TITLEATTRS=style-element | style-element (text-options) | (text-options)
specifies the color and font attributes of the global legend title. See General Syntax for Attribute Options for the syntax on using a style-element and Text Options for available text-options.
Default: The GraphLabelText style element.
Interaction: For this option to have any effect, the TITLE= option must also be specified.
TYPE= ROW | COLUMN
specifies whether nested legends are arranged into a single row or column.
Default: ROW
Interaction: When this option is set to ROW, the relative width of each legend is determined by the setting for the WEIGHTS= option.
WEIGHTS= UNIFORM | PREFERRED | (weight-list)
Specifies the preferred space allocation for the nested legends.
Default: UNIFORM
UNIFORM All nested legends get an equal amount of space.
PREFERRED All nested legends get their preferred amount of space.
(weight-list) A space-delimited list of preferred space allocations, enclosed in parentheses. The list can combine numbers with the keyword PREFERRED. Each number is a proportional weight for the corresponding nested legend (the weights do not have to sum to 1.0). Keyword PREFERRED specifies that the corresponding nested legend should be allocated its preferred space. The order of the weights that are specified in the list should correspond to the order of the legend statements that are nested in the GLOBALLEGEND layout.
Restriction: The option is supported only for TYPE=ROW.
Tip: When a weight-list is specified, all the legends using PREFERRED get their preferred space. Any remaining space is divided among the legends, in proportion to the numeric values specified in the weight-list.