Using the ODS escape character to create styled text


The Output Delivery System (ODS) functionality in SAS language programs is used to create formatted output in different file types such as PDF or RTF. In ODS you can use the ODS escape character to enable you to create styled text.

The ODS escape character is specified with the statement:

ODS ESCAPECHAR='char'

where char is the character used in subsequent SAS language statements in your program to define styled text. There is no default. This enables you to choose a character that is not included in the text you want to output, for example:

ODS ESCAPECHAR ="~";

The escape character can be specified in SAS language statements that can be used to output styled text. Using an escape character in these statements requires a specific syntax, the format is:

'ods-esc-char{STYLE style-element-name [style-attribute=style-value]text}'

where:

ods-esc-char

The character used as the ODS escape character.

style-element-name

This is the name of an ODS style element to be applied, which can then be modified by style-attribute if required. This is optional.

style-attribute

A text attribute, such as its font face, font style or colour. The attribute is identified by a keyword, such as FONT_FACE or FONT_STYLE.

style-value

The value that can be applied as Arial for FONT_FACE or ITALIC for FONT_STYLE.

text

The text to which the styling will apply. You can include further escape character formatting within this text.

There are various statements in the SAS language where you can use styled text, such as the ODS TEXT statement or the global TITLE statement, for example:

ODS TEXT='~{STYLE [COLOR=GREY FONT_STYLE=ITALIC]Test text }';

The ODS TEXT statement can be used in a SAS language program to output the styled text to a specified file type. For example, the following program creates a PDF file containing the defined styled text:

ODS ESCAPECHAR ="~";

ODS PDF FILE="c:\temp\odstext.pdf";
ODS TEXT='~{STYLE [COLOR=GREY FONT_STYLE=ITALIC]Test text }';
ODS PDF CLOSE;

writes the following text to the specified PDF:

Test text

Multiple SAS language statements can use the escape character once specified; for example, If you add a TITLE global statement to the previous program:

ODS ESCAPECHAR ="~";

TITLE1 JUSTIFY=LEFT
      '~{STYLE [FONT_FACE="Arial" FONT_SIZE=30pt COLOR=RED]Title 1}';
ODS PDF FILE="c:\temp\odstext.pdf";
ODS TEXT='~{STYLE [COLOR=GREY FONT_STYLE=ITALIC]Test text }';
ODS PDF CLOSE;

 the styled text is written to the specified PDF:

ods_pdf.png

Other articles that might be of interest: