TEMPLATE Procedure: Creating Table Templates

CELLSTYLE AS Statement

Sets the style element of the cells in the table or column according to the values of the variables. Use this statement to set the presentation characteristics (such as foreground color and font face) of individual cells.
Restriction: The CELLSTYLE AS statement can be used only within a column template or a table template.
Setting the Style Element for Cells Based on Their Values

Syntax

Required Arguments

expression
is an expression that is evaluated for each table or column cell that contains a variable.
If expression resolves to TRUE (a nonzero value), the style element that is specified is used for the current cell. If expression is FALSE (zero), the next expression in the statement is evaluated. Thus, you can string multiple expressions together to format cells conditionally.
expression has this form:
expression-1 <comparison-operator expression-n>
expression
is an arithmetic or logical expression that consists of a sequence of operators and operands. An operator is a symbol that requests a comparison, logical operation, or arithmetic calculation. An operand is one of the following:
constant
is a fixed value such as the name of a column or symbols that are declared in a DYNAMIC, MVAR, or NMVAR statement in the current template.
SAS function
specifies a SAS function. For information about SAS functions, see SAS Functions and CALL Routines: Reference.
built-in variable
is a special type of WHERE expression operand that helps you find common values in table or column templates. Built-in variables are one or more of the following:
_COLUMN_
is a column number. Column numbering begins with 1.
_DATANAME_
is a data column name.
_DATATYPE_
is the data type of the column variable. The data type is either numeric ("num") or character ("char").
Example:The following CELLSTYLE AS statement specifies that numeric column variables have a red font color and character column variables have a blue font color:
cellstyle   _datatype_ = "num" as {color=red},
            _datatype_ = "char" as {color=blue};
_LABEL_
is a column label.
_ROW_
is a row number. Row numbering begins with 1.
_STYLE_
is a style element name.
See:For a table of style element names, see ODS Style Elements.
_VAL_
is the data value of a cell.
Tip:Use _VAL_ to represent the value of the current column.
comparison-operator
compares a variable with a value or with another variable. The following table lists the comparison operators:
Comparison Operators
Symbol
Mnemonic Equivalent
Definition
=
EQ
Equal to
^= or ~= or ¬= or <>
NE
Not equal to
>
GT
Greater than
<
LT
Less than
>=
GE
Greater than or equal to
<=
LE
Less than or equal to
IN
Equal to one from a list of values
Tip:Using an expression of 1 as the last expression in the CELLSTYLE AS statement sets the style element for any cells that did not meet an earlier condition. For a table of style element names, see ODS Style Elements.
See:You can use any expression that can be used in the WHERE= data set option. For information about expressions that you can use in the WHERE data set option, see the WHERE data set option in SAS Data Set Options: Reference and the section on WHERE-Expression Processing in SAS Language Reference: Concepts.
style-attribute-specification
describes a style attribute to set. Each style-attribute-specification has this general form:
style-attribute-name=style-attribute-value
For information about the style attributes that you can set in a table template, see Style Attributes Overview.

Optional Argument

style-element-name
is the name of a style element that is part of a style that is registered with the Output Delivery System. SAS provides some styles. You can create customized styles and style elements with PROC TEMPLATE by using the DEFINE STYLE Statement. For a table of style element names, see ODS Style Elements.
The style elements that you would be most likely to use with the CELLSTYLE AS statement are
  • Data
  • DataFixed
  • DataEmpty
  • DataEmphasis
  • DataEmphasisFixed
  • DataStrong
  • DataStrongFixed
The style element provides the basis for displaying the cell. Additional style attributes modify the display.
Default:Data

For a table of style element names, see ODS Style Elements.