TEMPLATE Procedure: Creating Table Templates

DEFINE COLUMN Statement

Creates a template for a column.
Requirement: An END statement must be the last statement in the template.
Interaction: A column template can include one or more header templates.
See: DEFINE HEADER Statement
Setting the Style Element for Cells Based on Their Values

Setting the Style Element for a Specific Column, Row, and Cell

Creating Master Templates

Syntax

DEFINE COLUMN column-path | Base.Template.Column
CELLSTYLE expression-1 AS <style-element-name><[style-attribute-specification(s)] >
<, expression-n AS <style-element-name><[style-attribute-specification(s)]>>;
COMPUTE AS expression;
DEFINE HEADER | Base.Template.Header template-path;
statements-and-attributes
END;
DYNAMIC variable-1 <=default-variable-1>
<'text-1'>
<... variable-n <=default-variable-n><'text-n'>>;
MVAR variable-1 <=default-variable-1><'text-1'>
<... variable-n <=default-variable-n><'text-n'>>;
NMVAR variable-1 <=default-variable-1><'text-1'>
<... variable-n <=default-variable-n><'text-n'>>;
NOTES "text";
TRANSLATE expression-1 INTO expression-2
<, expression-n INTO expression-m>;
END;

Required Arguments

column-path
specifies where to store the column template. A column-path consists of one or more names that are separated by periods. Each name represents a directory in a template store, which is a type of SAS file. PROC TEMPLATE writes the template to the first writable template store in the current path.
Restrictions:If the template is nested inside another template, template-path must be a single-level name because the nested template is stored in the same location as the original template.

To reference the template that you are creating from another template, do not nest the template inside another one. For example, to reference a column template from multiple tables, do not define the column inside a table template.

Base.Template.Column
creates a master column template that is globally applied to all of your tabular output. After you create this template, you do not need to specify it explicitly in your SAS programs. It is automatically applied to all tabular output until you specifically remove the template from the item store.
Interaction:The Base.Template.Column master template attributes are overridden by other table templates.

Optional Argument

STORE=libref.template-store
specifies the template store in which to store the template. If the template store does not exist, it is created.
Restrictions:If the template is nested inside another template, do not use the STORE= option for the nested template because it is stored in the same location as the original template.

The STORE= option does not become part of the template.

Column Attribute Statements

This section lists all of the attributes that you can use in a column template. For all of the attributes that support a value of ON, these forms are equivalent:
ATTRIBUTE-NAME
ATTRIBUTE-NAME=ON
For all of the attributes that support a value of variable, variable is any variable that you declare in the column template with the DYNAMIC, MVAR, or NMVAR statement. If the attribute is Boolean, then the value of variable should resolve to either true or false as shown in this table:
Boolean Values
True
False
ON
OFF
_ON_
_OFF_
1
0
TRUE
FALSE
YES
NO
_YES_
_NO_
Column Attributes
Task
Attribute
Destinations
Influence the appearance of the cells contents
Specify whether to suppress the value of a variable from one row to the next, if the value does not change based on the formatted value of the variable
All except OUTPUT
Specify whether to suppress the value of a variable from one row to the next if the value does not change based on the raw value of the variable
All except OUTPUT
Select the best format for a column of a table
All
Specify whether to wrap the text in the current column
LISTING
Specify the format for the column
All
Specify the number of decimals for the column if it is not specified with FORMAT= column attribute
All
Specify the format width for the column if it is not specified with FORMAT= column attribute
All
Supply a numeric value against which values in the column are compared to eliminate trivial values from printing
All except OUTPUT
Specify the horizontal justification of the format field within the column (and for the column header if the template for the header does not include JUST=)
All except OUTPUT
Specify whether to justify the format field within the column, or to justify the value within the column, without regard to the format field
All destinations except LISTING behave as if JUSTIFY=ON
When the text in the column uses more than one line, specify whether to try to divide the text equally among all lines or to maximize the amount of text in each line
LISTING
Specify whether to draw a continuous line in the current column above the first table footer or below the last row of the column if there is no table footer
LISTING
Specify whether to treat the text as preformatted text
Markup family, printer family, and RTF
Specify whether to print the column
All except OUTPUT
Specify a separator character to append to each value in the column
LISTING
Specify the style element and style attributes to use for the column
Markup family, printer family, and RTF
Specify that the text graphic columns be turned off when a procedure is going to output a graph
All except OUTPUT and DOCUMENT
Specify the split character for the data in the column
All except OUTPUT
Specify whether to draw a continuous line in the current column below the column header, or above the first row of the column if there is no column header
LISTING
Specify the vertical justification for the column
Markup family, printer family, and RTF
Specify the width of the column in characters
LISTING
Specify the maximum width for this column
LISTING
Customize column headers
Specify the text for the column header or the name of the header template
All
Specify whether to print the column header
All except OUTPUT
Influence the relationship to other columns
Specify whether the column template is generic (that is, whether more than one variable use the template)
All except OUTPUT
Specify whether the column is an ID column
LISTING and printer family
Specify whether to merge the current column with the column immediately to its right
All except OUTPUT
Specify whether to merge the current column with the column immediately to its left
All except OUTPUT
Specify the number of blank characters to leave between the current column and the column immediately to its left
LISTING
Specify the number of blank characters to leave between the current column and the column immediately to its right
LISTING
Influence the presentation of data panels
Influence the place at which ODS splits a table when it creates multiple data panels
LISTING, printer family, and RTF
Specify whether to delete the current column from the output object if doing so enables all the remaining columns to fit in the space that is provided without splitting the table into multiple data panels
LISTING
Other column attributes
Specify which format to use if both a column template and a data component specify a format
All
Specify the name of the column in the data component to associate with the current column
All
Specify which special characters in headers for generic columns are to be used as split characters
All
Specify whether to include the column in an output data set
OUTPUT
Specify a label for the column
OUTPUT
Specify the column template that the current template inherits from
All
Specify the name to use for the corresponding variable in an output data set
OUTPUT
BLANK_DUPS<=ON | OFF | variable>;
specifies whether to suppress the value of a variable from one row to the next if the value does not change according to the formatted value of the variable.
Default:OFF
Interaction: If the CLASSLEVELS= table attribute is in effect, then ODS ignores BLANK_DUPS=ON when any value changes in a preceding column that is also marked with BLANK_DUPS=ON.
Tips:The BLANK_DUPS attribute is valid in all destinations except the OUTPUT destination.

When the PRINTER destination suppresses the value of a variable, it also suppresses the horizontal rule above the blank cell.

BLANK_INTERNAL_DUPS<=ON | OFF | variable>;
specifies whether to suppress the value of a variable from one row to the next if the value does not change according to the raw value of the variable.
Default:OFF
Interaction:If the CLASSLEVELS= table attribute is in effect, then ODS ignores BLANK_INTERNAL_DUPS=ON when any value changes in a preceding column that is also marked with BLANK_INTERNAL_DUPS=ON.
Tips:The BLANK_INTERNAL_DUPS attribute is valid in all destinations except the OUTPUT destination.

When the PRINTER destination suppresses the value of a variable, it also suppresses the horizontal rule above the blank cell.

CHOOSE_FORMAT= COMPROMISE | MAX | MAX_ABS | MIN_MAX;
selects a format based on the actual values in the column of the table.
COMPROMISE
looks at all of the values in the column and selects a good compromise format that works well for most values, but extreme values might shift to BEST format.
Tips:FORMAT_NDEC=d specifies the precision in digits.

The FORMAT_WIDTH= option suggests a maximum width. The actual format width might be smaller or it might be larger.

MAX
selects a format based on the maximum value in the column. Values are all expected to be positive so no space is reserved for a minus sign.
Default:By default, FORMAT_WIDTH=10 and FORMAT_NDEC= is ignored.
MAX_ABS
selects a format based on the maximum absolute value in the column. The format reserves space for a minus sign whether it is needed or not.
MIN_MAX
selects a format based on the minimum and maximum value in the column. The format reserves space for a minus sign only where it is actually needed.
Interaction:If FORMAT_NDEC=d is specified, a maximum of d decimal places is used.
Default:If you omit the CHOOSE_FORMAT column attribute, then the default format is determined by either the data component or other attributes.
Restriction:CHOOSE_FORMAT is not supported for computed columns because those columns' values are computed outside of the data object.
Tips:If you specify a small value for the FORMAT_WIDTH= option, then CHOOSE_FORMAT might create a dw.3 format.

The CHOOSE_FORMAT= attribute is valid in all destinations.

See:For more information about column formats, see Formatting Values in Table Columns.
DATA_FORMAT_OVERRIDE<=ON | OFF | variable>;
specifies which format to use if both a column template and a data component specify a format.
ON
uses the format in the data component.
OFF
uses the format in the column template.
variable
uses the format of the specified variable.
Default:OFF
Tip:The DATA_FORMAT_OVERRIDE attribute is valid in all destinations.
DATANAME=column-name;
specifies the name of the column in the data component to associate with the current column.
Default:By default, ODS associates the current column with a column of the same name in the data component.
Tip:The DATANAME= attribute is valid in all destinations.
DEF_SPLIT;
specifies that special characters in headers for generic columns are to be used as split characters.
Tip:The DEF_SPLIT destination is valid in all destinations.
DROP<=ON | OFF | variable>;
specifies whether to include the column in an output data set.
Default:OFF
Tip:The DROP attribute is valid only in the OUTPUT destination.
FLOW<=ON | OFF | variable>;
specifies whether to wrap the text in the current column if it is too long to fit in the space that is provided.
Default:ON if the format width of the column is greater than the column width. OFF if the format width of the column is not greater than the column width.
Tips:The FLOW attribute is valid only in the LISTING destination.

The HTML and PRINTER destinations always wrap the text if it is too long to fit in the space that is provided.

FORMAT=format-name <format-width <decimal-width>> | variable;
specifies the format for the column.
Default:If you omit the FORMAT= option, then the format that the data component provides is used. If the data component does not provide a format, ODS uses one of the following: BEST8. for integers, D12.3 for doubles, or the length of the variable for character variables.
Restriction:If you specify a format width for a numeric column, then its value cannot exceed 32.
Tip:The FORMAT= attribute is valid in all destinations.
FORMAT_NDEC= number | variable;
specifies the number of decimals for the column.
Default:The decimal width that is specified with the FORMAT= column attribute
Range:Number is a whole number from 0 to 32
Interaction:If you specify a decimal width using both the FORMAT= and the FORMAT_NDEC= attributes, then ODS uses the width that you specify with the FORMAT= attribute.
Tip:The FORMAT_NDEC= attribute is valid in all attributes.
FORMAT_WIDTH=positive-integer | variable;
specifies the format width for the column.
Default:If you omit the column attribute FORMAT_WIDTH=, then ODS uses the format specified in the FORMAT= attribute.
Range:1 to 32 for numeric variables; operating system limit for character variables
Interaction:If you specify a format width using both the FORMAT= and the FORMAT_WIDTH= attributes, then the width that you specify with the FORMAT= attribute is used.
Tip:The FORMAT_WIDTH= attribute is valid in all destinations.
FUZZ=number | variable;
supplies a numeric value against which to compare values in the column to eliminate trivial values from printing. A number whose absolute value is less than or equal to the FUZZ= value is printed as 0. However, the real value of the number is used in any computations based on that number.
Default:This is the smallest representable floating-point number on the computer that you are using.
Tip:The FUZZ= attribute is valid in all destinations except the OUTPUT destination.
GENERIC<=ON | OFF | variable>;
specifies whether the column template can be used by more than one column. Generic columns are useful in tables with many similar columns. For example, the table templates for both PROC SQL and the DATA step define only two columns: one for character variables and one for numeric variables. When a program runs, it determines which column template the data component should use for each column.
Default:OFF
Tip:The GENERIC attribute is valid in all destinations except the OUTPUT destination.
GLUE=integer | variable;
Influences the places at which ODS splits a table when it creates multiple data panels. ODS creates multiple data panels from a table that is too wide to fit in the allotted space. The higher the value of GLUE= is, the less likely it is that ODS will split the table between the current column and the column to its right.
Default:1
Range:-1 to 327
Tips:A value of -1 forces the table to split between the current column and the column to its right.

The GLUE= attribute is valid only in the LISTING, printer family, and RTF destinations.

HEADER=header-specification;
specifies the text for the column header or the name of the header template. header-specification is one of the following:
"text"
specifies the actual text of the header.
Requirement:text must be enclosed by quotation marks.
header-name
specifies the name of a header template to use. Create a header template with the DEFINE HEADER statement (see DEFINE HEADER Statement). If header-name is a single-level name, the header template must occur within the current column template.
variable
specifies the name of a variable declared with the DYNAMIC, MVAR, or NMVAR statement. The value of the variable becomes the column header.
_LABEL_
Uses the label that is specified in the data component for the column header.
Default:_LABEL_
Interaction:If you are using the OUTPUT destination, then the HEADER= attribute does not change the label of the variable in the data set. To change the label in the data set, use the LABEL= attribute.
Tips:The HEADER= option provides a simple way to specify the text of a column header. To customize the header further, use the DEFINE HEADER statement with the appropriate header attributes. (See DEFINE HEADER Statement.)

Use the split character in the text of the header to force the text to a new line.

The HEADER= attribute is valid in all destinations.

ID<=ON | OFF | variable>;
specifies whether the column is an ID column. An ID column is repeated on each data panel. (ODS creates multiple data panels when a table is too wide to fit in the allotted space.)
Default:OFF
Tips:ODS treats all columns up to and including a column that is marked with ID=ON as ID columns.

The ID attribute is valid only in LISTING and printer family destinations.

JUST=justification | variable;
specifies the horizontal justification of the format field within the column (and of the header if the template for the header does not include JUST=).
justification is one of the following:
CENTER
specifies center justification.
Alias:C
Interaction:To use center justification in printer family and RTF destinations, also specify JUSTIFY=ON.
DEC
specifies aligning the values by the decimal point.
Alias:D
Restriction:Decimal alignment is supported for printer family and RTF destinations only.
LEFT
specifies left justification.
Alias:L
RIGHT
specifies right justification.
Alias:R
Default:LEFT for columns that contain character values; RIGHT for columns that contain numeric values.
Interactions:The TEXTALIGN= style attribute overrides the value of JUST=.

For the LISTING destination, ODS justifies the format field within the column width. At times, you can specify the JUSTIFY= attribute to get the results that you want. See the discussion of the JUSTIFY attribute.

Tip:The JUST= attribute is valid in all destinations except the OUTPUT destination.

FORMAT= and WIDTH=

JUSTIFY<=ON | OFF | variable>;
specifies whether to justify the format field within the column or to justify the value within the column without regard to the format field.
Default:OFF
Interaction:JUSTIFY=ON can interfere with decimal alignment in the LISTING destination.
Tips:If you translate numeric data to character data, you might need to use JUSTIFY= to align the data.

All destinations except the LISTING destinations justify values as if JUSTIFY=ON.

LABEL="text" | variable;
specifies a label for the column in the output data set.
Default:If you omit a label, ODS uses the label that is specified in the data component. If no label is specified in the data component, ODS uses the header for the column as the label.
Tips:The LABEL= attribute is valid only in the OUTPUT destination.

If the OUTPUT destination is open, then the LABEL= attribute provides a label for the corresponding variable in the output data set. This label overrides any label that is specified in the data component.

MAXIMIZE<=ON | OFF | variable>;
specifies whether to try to divide the text equally among all lines or to maximize the amount of text in each line when the text in the column uses more than one line. For example, if the text spans three lines, MAXIMIZE=ON can result in 45% of the text on the first line, 45% of the text on the second line, and 10% of the text on the third line. MAXIMIZE=OFF can result in 33% of the text on each line. MAXIMIZE=ON can write lines of text that vary greatly in length. MAXIMIZE=OFF can result in using less than the full column width.
Default:OFF
Interaction:This attribute is effective only if the column is defined with FLOW=ON. (See the discussion of the FLOW= column attribute).
Tip:The MAXIMIZE= attribute is valid only in the LISTING destination.
MERGE<=ON | OFF | variable>;
specifies whether to merge the current column with the column immediately to its right. When you set MERGE=ON for the current column, the data in each row of the column is merged with the data in the same row of the next column. ODS applies the format, justification, spacing, and prespacing attributes to each column independently. Then, it concatenates the columns. Finally, it applies to the concatenated data all the remaining attributes that are specified on the column that does not have MERGE= set.
Default:OFF
Restriction:You cannot use both MERGE=ON and PRE_MERGE=ON in the same column template. You cannot merge or premerge a column with another column that has either MERGE=ON or PRE_MERGE=ON. Note that you can merge three columns by setting MERGE=ON for the first column, no merge or premerge attributes for the second column, and PRE_MERGE=ON for the third column.
Tip:The MERGE= attribute is valid in all destinations except the OUTPUT destination.
OPTIONAL<=ON | OFF | variable>;
specifies whether to delete the current column from the output object if doing so enables all the remaining columns to fit in the space that is provided without splitting the table into multiple data panels.
Default:OFF
Interaction:If multiple column templates contain OPTIONAL=ON, either all or none of these columns are included in the output object.
Tip:The OPTIONAL attribute is valid only in the LISTING destination.
OVERLINE<=ON | OFF | variable>;
specifies whether to draw a continuous line in the current column above the first table footer (or, if there is no table footer, below the last row of the column). The second formatting character is used to draw the line.
Default:OFF
Tip:The OVERLINE= attribute is valid only in the LISTING destination.
See:For information about formatting characters, see the FORMCHAR= table attribute.
PARENT=variable;
specifies the column template from which the current template inherits attributes and statements. A column-path consists of one or more names that are separated by periods. Each name represents a directory in a template store, which is a type of SAS file. The current template inherits from the specified column in the first readable template store in the current path.
When you specify a parent, all of the attributes and statements that are specified in the parent's template are used in the current template unless the current template specifically overrides them.
Tip:The PARENT= attribute is valid in all destinations.
PREFORMATTED<=ON | OFF | variable>;
specifies whether to treat the text as preformatted text. When text is preformatted, ODS honors line breaks as well as leading, trailing, and internal spaces. It also displays the text in a monospace font.
Default:OFF
Interaction:When PREFORMATTED=ON, ODS uses the DataFixed style element unless you specify another style element with the STYLE= column attribute.
Tip:The PREFORMATTED attribute is valid in the markup family, printer family, and RTF destinations.
PRE_MERGE<=ON | OFF | variable>;
specifies whether to merge the current column with the column immediately to its left. When you set PRE_MERGE=ON for the current column, the data in each row of the column is merged with the data in the same row of the previous column. ODS applies the format, justification, spacing, and prespacing attributes to each column independently. Then, it concatenates the columns. Finally, it applies to the concatenated data all the remaining attributes that are specified on the column that does not have PRE_MERGE= set.
Default:OFF
Restriction:You cannot use both MERGE=ON and PRE_MERGE=ON in the same column template. You cannot merge or premerge a column with another column that has either MERGE=ON or PRE_MERGE=ON. Note that you can merge three columns by setting MERGE=ON for the first column, no merge or premerge attributes for the second column, and PRE_MERGE=ON for the third column.
Tip:The PRE_IMAGE attribute is valid in all destinations except the OUTPUT destination.
PRE_SPACE=non-negative-integer;
specifies the number of blank characters to leave between the current column and the column immediately to its left.
Default:A value in the range that is bounded by the COL_SPACE_MIN and COL_SPACE_MAX table attributes.
Interaction:If PRE_SPACE= and SPACE= are specified for the same intercolumn space, ODS honors PRE_SPACE=.
Tip:The PRE_SPACE= attribute is valid only in the LISTING destination.
PRINT<=ON | OFF | variable>;
specifies whether to print the column.
Default:ON
Interaction:If you specify the column attribute PRINT=OFF, then you turn off the value of a column if it is part of a stacked column. If all columns in a stacked column have PRINT=OFF set, then the entire column is removed from the table.
Tips:If all columns in a stacked column have PRINT=OFF specified, then the entire column is removed from the table.

The PRINT attribute is valid in all destination except the OUTPUT destination.

PRINT_HEADERS<=ON | OFF | variable>;
specifies whether to print the column header and any underlining and overlining.
Default:ON
Tip:The PRINT_HEADERS attribute is valid in all destination except the OUTPUT destination.
SEPARATOR="character" | variable;
specifies a separator character to append to each value in the column.
Default:None
Restriction:The SEPARATOR= column attribute is valid only for character variables.
Tips:To specify a hexadecimal character as the separator character, put an x after the closing quotation mark. For example, this option assigns the hexadecimal character 2-D as the separator character: separator="2D"x

The SEPARATOR= attribute is valid only in the LISTING destination.

SPACE=positive-integer | variable;
specifies the number of blank characters to leave between the current column and the column immediately to its right.
Default:A value in the range that is bounded by the COL_SPACE_MIN and COL_SPACE_MAX table attributes.
Interaction:If PRE_SPACE= and SPACE= are specified for the same intercolumn space, ODS honors PRE_SPACE=.
Tip:The SPACE= attribute is valid only in the LISTING destination.
STYLE=<style-element-name><[style-attribute-specification(s)]>;
specifies the style element and any changes to its attributes to use for the current column. Neither style-attribute-specification nor style-element-name is required. However, you must use at least one of them.
Note: You can use braces ({ and }) instead of square brackets ([ and ]).
style-element-name
is the name of the style element to use to display the data in the column. The style element must be part of a style that is registered with the Output Delivery System. SAS provides some styles. You can create customized styles with PROC TEMPLATE (see TEMPLATE Procedure: Creating a Style Template).
By default, ODS displays different parts of ODS output with different style elements. For example, by default, the data cells in a column are displayed with the style element Data. You would be most likely to use the following style elements with the STYLE= column attribute:
  • Data
  • DataFixed
  • DataEmpty
  • DataEmphasis
  • DataEphasisFixed
  • DataStrong
  • DataStrongFixed
The style element provides the basis for displaying the column. Additional style attributes that you provide can modify the display.
For information about viewing a style so that you can see the style elements that are available, see Viewing the Contents of a Style. For information about the default style that ODS uses, see Modifying Style Elements in the Default Style for HTML and Markup Languages.
style-element-name is either the name of a style element or a variable whose value is a style element. For a table of style element names, see ODS Style Elements.
Default:Data
style-attribute-specification
describes the style attribute to change. Each style-attribute-specification has this general form:
style-attribute-name=style-attribute-value
For information about the style attributes that you can specify, see Style Attributes Overview.
Tips:The STYLE= attribute is valid only in the markup family, printer family, and RTF destinations.

If you use the STYLE= attribute inside a quoted string, then add a space before or after the carriage return to prevent errors. SAS does not interpret a carriage return as a space. You must explicitly specify spaces in quoted strings.

TEXT_GRAPHIC= ON | OFF;
specifies that the text graphic columns be turned off or on when a procedure is going to output a graph.
Default:OFF
TEXT_SPLIT="character" | variable;
specifies the split character for the data in the column. The value in the column is broken when it reaches that character and continues the value on the next line. The split character itself is not part of the data and does not appear in the column.
Default:None
Tip:The TEXT_SPLIT= attribute is valid in all destinations except the OUTPUT destination.
UNDERLINE<=ON | OFF | variable>;
specifies whether to draw a continuous line in the current column below the column header (or, if there is no column header, above the first row of the column). The second formatting character is used to draw the line.
Default:OFF
Tip:The UNDERLINE= attribute is valid only in the LISTING destination.
See:For information about formatting characters, see the FORMCHAR= table attribute.
VARNAME=variable-name | variable;
specifies the name to use for the corresponding variable in an output data set.
Default:If you omit VARNAME=, then the value of the DATANAME= attribute is used. If you omit DATANAME=, then the name of the column is used.
Tips:If you use VARNAME= to specify the same name for different columns, a number is appended to the name each time that the name is used.

The VARNAME= attribute is valid only in the OUTPUT destination.

VJUST=justification | variable;
Specifies the vertical justification for the column. justification is one of the following:
TOP
places the first line of text as high as possible.
Alias:T
CENTER
centers the text vertically.
Alias:C
BOTTOM
places the last line of text as low as possible.
Alias:B
Default:TOP
Tip:The VJUST= attribute is valid only in the markup family, printer family, and RTF destinations.
WIDTH= positive-integer | variable;
specifies the width of the column in characters.
Default:If you omit a width, the format width is used. If the column has no format associated with it, ODS uses one of the following widths: 8 for integers, 12 for doubles, or data length for character variables.
Interaction:The length of the column header can influence the width of the column.
Tip:The WIDTH= attribute is valid only in the LISTING destination.
WIDTH_MAX= positive-integer | variable;
specifies the maximum width allowed for this column. By default, PROC TEMPLATE extends the width of the column if the header is wider than the data. The width of the column can be anywhere between the values of WIDTH= and WIDTH_MAX=.
Default:The width of the format for the column
Tip:The WIDTH_MAX= attribute is valid only in the LISTING destination.