text in the available space. You can also use the TEXTFITPOLICY= and/or
SHORTTEXT= options.
The following long title uses the default fit policy, which is to wrap text that does not fit
on a single line:
entrytitle "This is a lot of text to display on one line";
Here is the output.
Notice that the current horizontal alignment (CENTER in this case) is used when text
wraps. Text is wrapped only at word boundaries (a space).
Here is the output when the fit policy is set to TRUNCATE.
The ellipsis in the output text indicates where the truncation occurs. Rather than
truncating text, you can specify alternative "short" text to substitute whenever the
primary text does not fit without wrapping in the available space.
entrytitle "This is a lot of text to display on one line" /
textfitpolicy=short shorttext=("Short alternative text");
Here is the output.
ENTRY Statements: Additional Control
Features Available for ENTRY Text
ENTRY statements are more flexible than ENTRYTITLE or ENTRYFOOTNOTE
statements and support additional features for automatically positioning text, aligning
text vertically, and rotating text:
AUTOALIGN= NONE | AUTO | (location-list)
Specifies whether the entry is automatically aligned within its parent when nested
within an overlay-type layout.
ROTATE= 0 | 90 | 180 | 270
Specifies the angle of text rotation.
VALIGN= CENTER | TOP | BOTTOM
Specifies the vertical alignment of the text.
294 Chapter 15 Adding Titles, Footnotes, and Text Entries to Your Graph
Positioning ENTRY Text
By default, any ENTRY statement that is defined within a 2-D overlay-type layout and
does not specify a location is placed in the center of the graph wall (HALIGN=CENTER
VALIGN=CENTER). If you know where you want to place the text, one way to position
it is to use the HALIGN= and VALIGN= options, as shown in the following example:
proc template;
define statgraph textentry;
begingraph;
layout overlay / pad=0;
scatterplot x=height y=weight;
entry halign=left "NOBS = 19" /
valign=top border=true;
endlayout;
endgraph;
end;
run;
proc sgrender data=sashelp.class template=textentry;
run;
Here is the output.
Whenever you add text within the graph wall, you have to consider the possibility that
the text might appear on top of or behind data markers and plot lines. For this reason,
you should consider using the AUTOALIGN= option rather than the HALIGN= and
VALIGN= options for positioning the text.
The AUTOALIGN= option enables you to set a priority list that restricts the entry
location to certain locations. The priority list can include any of the keywords
TOPLEFT, TOP, TOPRIGHT, LEFT, CENTER, RIGHT, BOTTOMLEFT, BOTTOM,
and BOTTOMRIGHT.
In the following histogram, we know that the best location for an entry is either
TOPLEFT or TOPRIGHT, depending on the skewness of the data.
ENTRY Statements: Additional Control 295
With the following layout block, if the data were skewed to the right so that the entry
text overlaps with the histogram, the text would automatically appear at TOPLEFT.
layout overlay;
histogram weight;
entry "NOBS = 19" /
autoalign=(topright topleft)
border=true;
endlayout;
When the parent layout contains only scatter plots, the ENTRY statement can use the
AUTOALIGN=AUTO setting to automatically position the text where it is the farthest
away from any scatter points. In all cases, even one like the following layout block
where many positions are available that might minimize data collision, the AUTO
specification selects the position for you and you have no further control over the text
position.
layout overlay;
scatterplot x=height y=weight;
entry halign=left "NOBS = 19" /
autoalign=auto border=true;
endlayout;
Here is example output.
Rotating ENTRY Text
For the ENTRY statement, the ROTATE= option can be used to rotate the entry text. For
example, ENTRY statements can be used to define the text that appears in a
CELLHEADER block in a LATTICE layout. You can also use ENTRY statements in
SIDEBAR, ROWHEADERS, and COLUMNHEADERS blocks. In the following code
296 Chapter 15 Adding Titles, Footnotes, and Text Entries to Your Graph
fragment, the ROTATE= option in the ROWHEADERS block rotates the row headers
90 degrees in a lattice layout.
rowheaders;
layout gridded / columns=2;
entry "Volume" / textattrs=GraphLabelText rotate=90;
entry "(Millions of Shares)" / textattrs=GraphValueText rotate=90;
endlayout;
layout gridded / columns=2;
entry "Price" / textattrs=GraphLabelText rotate=90;
entry "(Adjusted Close)" / textattrs=GraphValueText rotate=90;
endlayout;
endrowheaders;
Here is the result.
The complete code for this example is shown in “Example 4: Lattice with Row Headers”
on page 220.
ENTRY Statements: Additional Control 297
298 Chapter 15 Adding Titles, Footnotes, and Text Entries to Your Graph

Get SAS 9.4 Graph Template Language, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.