LEGENDITEM Statement

LEGENDITEM Description and Syntax

Creates the definition for a legend item that can be included in a discrete legend.
LEGENDITEM TYPE=type NAME="string" </option(s)>;

LEGENDITEM Example Graph

The following graph was generated by the LEGENDITEM Example Program. The example specifies three LEGENDITEM statements to define graphical properties for two marker symbols and a text string. The NAME= option on each LEGENDITEM statement assigns a name to the definition. Those names are referenced in a DISCRETELEGEND statement so that the definitions are displayed in the graph legend. To correlate the legend with the scatter plot, the example creates an attribute map that matches values M and F to the same graphical properties that are specified in the LEGENDITEM statements. That attribute map is referenced in the scatter plot.
Customizing Legend Items

LEGENDITEM Example Program

proc template;
  define statgraph scatterplot;
    begingraph;
      entrytitle "Team Tryouts: Height and Weight by Sex";
      discreteattrmap name="symbols" / ignorecase=true trimleading=true;
        value "m"    / markerattrs=(color=blue symbol=diamondfilled);
        value "f"    / markerattrs=(color=red  symbol=circlefilled); 
      enddiscreteattrmap;
      discreteattrvar attrvar=groupmarkers var=sex attrmap="symbols";
      legendItem type=marker name="m_marker" /
        markerattrs=(color=blue symbol=diamondfilled)
        label="70% of boys present" ;
      legendItem type=marker name="f_marker" /
        markerattrs=(color=red  symbol=circlefilled)
        label="75% of girls present" ;
      legendItem type=text name="status" /
        text=" (5 health forms missing)" ;
      layout overlay;
        scatterplot x=height y=weight / group=groupmarkers;
        discretelegend "m_marker" "f_marker" "status" /
          autoitemsize=true;
      endlayout;
    endgraph;
  end;
proc sgrender data=sashelp.class template=scatterplot;
run;

LEGENDITEM Summary

The LEGENDITEM statement creates a definition for a legend item that can be included in a legend. The item that you define is independent of the data and enables you to customize the legend to enhance or replace a standard legend. For example, to display annotation text within the legend area, you can define a LEGENDITEM statement with TYPE=TEXT and specify the text in the TEXT= option.
As demonstrated in the LEGENDITEM Example Program, multiple LEGENDITEM statements can be used to replace a plot statement’s data-driven legend by defining custom legend items to display in the legend. This use enables you to communicate information that is not in the data. For this use, you would define one or more LEGENDITEM statements to specify legend attributes, and then reference those items in your legend statement. You must not reference the plot statement itself in the legend statement. Although no direct connection would exist between the plot data and the legend, you could communicate the connection by managing the visual attributes in both the plot and the legend.
The LEGENDITEM statement must be located within the BEGINGRAPH block but outside of the outermost layout block. You can use multiple LEGENDITEM statements to define multiple definitions. In that case, each definition specifies a single legend entry and each item name must be referenced in the legend statement.
Note: A single legend statement can reference multiple item names and also multiple plot names.
When specifying attribute options for a particular LEGENDITEM statement, options that do not apply to the specified TYPE= value are ignored. For example, the MARKERATTRS= option sets the attributes for a marker and is useful if you set TYPE=MARKER or TYPE=MARKERLINE. However, if TYPE= is set to a value that does not display a marker symbol, the MARKERATTRS= option is ignored.

LEGENDITEM Required Arguments

TYPE = FILL | MARKER | MARKERLINE | LINE | TEXT
specifies a type for the legend item.
FILL specifies a fill (displayed as a filled square). The appearance can be managed with the FILLATTRS= and OUTLINEATTRS= options.
MARKER specifies a marker. The appearance can be managed with the MARKERATTRS= option.
MARKERLINE specifies a marker and a line. The appearance can be managed with the MARKERATTRS= and LINEATTRS= options.
LINE specifies a line. The appearance can be managed with the LINEATTRS= option.
TEXT specifies text that can be displayed in the legend area. The text string is defined with the TEXT= option, and the text appearance can be managed with the TEXTATTRS= option.
NAME="string"
assigns a name to the legend item for reference in a DISCRETELEGEND or MERGEDLEGEND statement.
Restriction: The string is case sensitive and must define a unique name within the template.

LEGENDITEM Options

Statement Option
Description
Specifies the color of the fill when TYPE= is set to FILL.
Specifies a label to be used for the legend item.
Specifies the color and font attributes of the legend item’s label.
Specifies the appearance of the line when TYPE= is set to LINE or MARKERLINE.
Specifies the appearance of the marker when TYPE= is set to MARKER or MARKERLINE.
Specifies the color of the outline when TYPE= is set to FILL.
Specifies the text to display when TYPE= is set to TEXT.
Specifies the font and color attributes of the string that is specified on the TEXT= option when TYPE= is set to TEXT.
FILLATTRS=style-element | style-element (fill-options) | (fill-options)
specifies the color of the fill when TYPE= is set to FILL. See General Syntax for Attribute Options for the syntax on using a style-element and Fill Options for available fill-options.
Default: The GraphDataDefault style element.
Interaction: The TRANSPARENCY attribute cannot be derived from the style element, but it can be set with this option.
LABEL= "string"
specifies a label to be used for the legend item.
Default: no label is displayed
Tip: The font and color attributes for the label are specified by the LABELATTRS= option.
LABELATTRS
specifies the color and font attributes of the legend item’s label.
Default: The GraphValueText style element.
Interaction: For this option to take effect, the LABEL= option must also be specified.
LINEATTRS=style-element | style-element (line-options) | (line-options)
specifies the appearance of the line when TYPE= is set to LINE or MARKERLINE. See General Syntax for Attribute Options for the syntax on using a style-element and Line Options for available line-options.
Default: The GraphDataDefault style element.
MARKERATTRS=style-element | style-element (marker-options) | (marker-options)
specifies the appearance of the marker when TYPE= is set to MARKER or MARKERLINE. See General Syntax for Attribute Options for the syntax on using a style-element and Marker Options for available marker-options.
Default: The GraphDataDefault style element.
Interaction: The WEIGHT attribute cannot be derived from the style element, but it can be set with this option.
OUTLINEATTRS=style-element | style-element (line-options) | (line-options)
specifies the color of the outline when TYPE= is set to FILL. See General Syntax for Attribute Options for the syntax on using a style-element and Line Options for available line-options.
Default: The GraphDataDefault style element.
This option enables you to set the color. It ignores settings for the line pattern and line thickness.
TEXT= "string"
specifies the text to display when TYPE= is set to TEXT.
Default: a blank space
The font and color attributes for the text are specified by the TEXTATTRS= option.
TEXTATTRS=style-element | style-element (text-options) | (text-options)
specifies the font and color attributes of the string that is specified on the TEXT= option when TYPE= is set to TEXT. See General Syntax for Attribute Options for the syntax on using a style-element and Text Options for available text-options.
Default: The GraphValueText style element.