Managing the String on Text Statements

Text Statement Syntax

Options on the ENTRYTITLE, ENTRYFOOTNOTE, and ENTRY text statements enable you to create simple or complex text constructs. The following syntax shows the general form of these statements:
TEXT-STATEMENT text-item <...<text-item>> / <options>;
Any text-item is some combination of the following:
<prefix-option ...<prefix-option>> "string" | dynamic | character-expression |
{text-command}
What this means is that the final text that is to be created can be specified in a series of separate items, each with individual prefix options. Statement options can also affect the final text. These possibilities are explained by the examples in the following sections.

Using Rich Text

"Rich text" describes text in which each character can have different text properties. The following example creates rich text by separating the text into pieces and using prefix options to set different text properties for each piece. Properties that are set this way stay in effect for subsequent text items, unless changed by another TEXTATTRS= prefix option.
entrytitle textattrs=(size=12pt color=red) "Hello "
           textattrs=(size=10pt color=blue style=italic) "World"; 
Rich Text
For each horizontal alignment, the overall text for these statements is formed by the concatenation of the text items. Notice that there is no concatenation operator and that any spacing (such as word breaks) must be provided as needed within the strings ("Hello " "World"). The space that separates the text-item specifications is never included in the final text string.

Horizontally Aligning Text Items

Text items can have different horizontal alignments: LEFT, CENTER, or RIGHT. The default alignment is CENTER. Text items with the same alignment are gathered and concatenated.
entryfootnote halign=left textattrs=(weight=bold) "XYZ Corp."
              halign=right textattrs=(weight=normal) "30JUN08";
Horizontal Alignment of Text Items

Generating Text Items with Dynamics, Macro Variables, and Expressions

Text items are not limited to string literals. Text items can also be defined as dynamics, macro variables, or expressions. In the following example, SYSDATE is declared with an MVAR template statement. As a result, this automatic macro variable is resolved to today's date at run time.
entryfootnote halign=left textattrs=(weight=bold) "XYZ Corp."
              halign=right textattrs=(weight=normal) SYSDATE ;
Using a Macro Variable in a Text Item
This next example shows how the GTL EVAL function causes an expression to be evaluated at run time. In this case, the PUT function (same as the PUT function in the DATA step) is used to convert a SAS date value into a string:
entryfootnote "Summary for "  eval(put(today(),mmddyyd.)) ;
Using a PUT function in a Text Item
For more information about dynamics, macro variables, and EVAL expressions in GTL, see Using Dynamics and Macro Variables to Make Flexible Templates and Using Conditional Logic and Expressions.

Adding Subscripts, Superscripts, and Unicode Rendering

You can build strings with subscripts or superscripts using the {SUB "string" } or {SUP "string" } text commands. You can also use dynamics or macro variables for the string portion of the text command.
entryfootnote "R" {sup "2"} "=.457"; 
entryfootnote "for the H" {sub "2"} "O Regression" ;
Subscripts and Superscripts in Text
Another way to form text is to use the {UNICODE "hex-value"x } text command. For fonts that support Unicode code points, you can use the following syntax to render the glyph (character) corresponding to any Unicode value:
entryfootnote  {unicode "03B1"x} "=.05" ;
In the code, the "03B1"x is the hexadecimal code point value for the lowercase Greek letter alpha. Because Greek letters and some other statistical symbols are so common in statistical graphics, keyword short cuts to produce them have been added to GTL syntax. So another way of indicating "03B1"x is
entryfootnote  {unicode alpha} "=.05" ;
Unicodes in Text
For a complete list of keywords that can be used with the {unicode keyword} notation, see SAS Keywords for Unicode Glyphs. For rules regarding specifying Unicode and other special characters, see Rules for Unicode and Special Character Specifications in SAS Graph Template Language: Reference.
In addition, any Unicode glyph for currency, punctuation, arrows, fractions and mathematical operators, symbols, and dingbats can be used. Fonts such as Arial (comparable to SAS-supplied Albany AMT) have many, but not all, Unicode code points available, and sometimes a more complete Unicode font such as Arial Unicode MS (or SAS-supplied Monotype Sans WT J) needs to be specified. ODS styles have a style element named GraphUnicodeText that can be safely used for rendering any Unicode characters. The following example uses the GraphUnicodeText style element for rendering a bar over the X:
entry  "X"{unicode bar}"=6.78" / textattrs=GraphUnicodeText;
Glyphs in Text

Using Unicode Values in Labels

The {UNICODE}, {SUB}, and {SUP} text commands apply only to the ENTRY, ENTRYTITLE, and ENTRYFOOTNOTE statements. However, strings that are assigned to axis labels, curve labels, legend labels, and so on, can present Unicode characters using what is called "in-line formatting." To use this special formatting, you embed within the string an ODS escape sequence followed by a text command. Specifically, whenever you use an ODS ESCAPECHAR= statement to define an escape character, and then include that escape character in a quoted string, it signals that the next token represents a text command. Currently, only the {UNICODE} text command is recognized, not {SUB} or {SUP}. For rules regarding specifying Unicode characters, see Rules for Unicode and Special Character Specifications in SAS Graph Template Language: Reference.
In the following example, the alpha value for the upper and lower confidence limits is displayed using the Greek letter alpha:
ods escapechar="^"; /* Define an escape character */

proc template;
  define statgraph fit;
    begingraph;
      entrytitle "Regression Fit Plot with CLM Band";
      layout overlay;    
        modelband "clm" / display=(fill)  name="band"
          legendlabel="^{unicode alpha}=.05" ;
        scatterplot x=height y=weight / primary=true  ;
        regressionplot x=height y=weight / alpha=.05 clm="clm"
          legendlabel="Linear Regression" name="fit";
        discretelegend "fit" "band";
      endlayout;
    endgraph;
  end;
run;

proc sgrender data=sashelp.class template=fit;
run;
Adding an Escape Character to a Legend Label