Previous Page | Next Page

TEMPLATE Procedure: Creating Crosstabulation Table Templates

DEFINE CELLVALUE Statement


Defines a value that appears in the crosstabulation cells.
Featured in: Creating a Customized Crosstabulation Table Template with No Legend

DEFINE CELLVALUE <cellvalue>;
<cellvalue-attribute-1;><...cellvalue-attribute-n>;
CELLSTYLE expression-1 AS <style-element-name><[style-attribute-specification(s)] ><..., expression-n AS <style-element-name><[style-attribute-specification(s)]>>;
DYNAMIC variable-1<'text-1'> <... variable-n<'text-n'>>;
NOTES 'text';
END;

DEFINE CELLVALUE Statements
Task Statement
Set one or more cellvalue attributes cellvalue-attributes
Specify the style element of the cells in the column according to the values of the variables CELLSTYLE AS
Define a symbol that references a value that the data component supplies from the procedure DYNAMIC
Provide information about the crosstabulation table NOTES
End a cellvalue template END


Options

cellvalue

specifies one of the possible values that PROC FREQ can produce for a crosstabulation table. For a cellvalue to appear in a cell, it must meet one of these requirements:

  • specified in a DEFINE CELLVALUE statement

  • included in the CELLVALUE statement

  • not suppressed by one of the following options for the TABLES statement in PROC FREQ: NOFREQ, NOPERCENT, NOROW, NOCOL, or CUMCOL

  • requested by one of the following options: EXPECTED, DEVIATION, CELLCHI2, or TOTPCT

To prevent a cellvalue from appearing in a table, you need to change only one of the preceding specifications.

cellvalue is one of the following:

Frequency

is the frequency count.

Expected

is the expected frequency of the cell.

Deviation

is the deviation of the cell frequency from the expected value.

CellChiSquare

is the cell's contribution to the total Pearson chi-square statistic.

TotalPercent

is the percentage of total frequency on n-way tables when n>2.

Percent

is the percentage of the table frequency.

RowPercent

is the percentage of the row frequency.

ColPercent

is the percentage of the column frequency.

CumColPercent

is the cumulative percentage of the column frequency.


DEFINE CELLVALUE Attribute Statements

This section lists all the attribute statements that you can use in a cellvalue template and the tasks that are associated with the statements. For all attributes that support a value of ON, these forms are equivalent:

ATTRIBUTE-NAME
ATTRIBUTE-NAME=ON

DEFINE CELLVALUE Attribute Statements
Task Statement
Specify which format to use for the cellvalue if both a crosstabulation template and a data component specify a format DATA_FORMAT_OVERRIDE=
Specify the format for the cellvalue FORMAT=
Override the width specified by the FORMAT= attribute FORMAT_WIDTH=
Override the number of decimals specified by the FORMAT= attribute FORMAT_NDEC=
Specify the text in the legend HEADER=
For the Output destination, specify the label for the data set column corresponding to the cellvalue LABEL=
Specify whether a cellvalue appears in the crosstabulation table PRINT=

DATA_FORMAT_OVERRIDE=<ON | OFF>;

specifies which format to use if both a crosstabulation template and a data component specify a format for Frequency, Expected, and Deviation.

ON

selects the format specified in the data component.

OFF

selects the format specified in the crosstabulation template.

Default: OFF
Interaction: If you specify DATA_FORMAT_OVERRIDE=ON, and the FORMAT option is specified on the TABLES statement in PROC FREQ, then the data component will specify that format for the Frequency, Expected, and Deviation cellvalues.
FORMAT=format_name <format-width<decimal-width >>;

specifies the format for the column.

Default: If you omit the FORMAT= option, PROC TEMPLATE uses the format that the data component provides. If the data component does not provide a format, PROC TEMPLATE uses one of the following:
  • BEST8. for integers

  • 12.3 for floating-point values

  • the length of the variable for character variables

Interaction: For Listing output, the width of the cells is governed by the format width. Cells are at least one character wider than the format width.
Range: The minimum cell width is 8, and the maximum width is 25.
FORMAT_WIDTH=positive-integer

overrides the width specified by the FORMAT= attribute statement.

See also: FORMAT=
FORMAT_NDEC=positive-integer

overrides the number of decimals specified by the FORMAT= attribute statement.

See also: FORMAT=
HEADER='text'

specifies the text in the legend.

Tip: For Listing output, only the first 15 characters of text are displayed.
LABEL='text'

for the Output destination, specifies the label for the data set column that corresponds to the cellvalue.

PRINT= ON | OFF

specifies whether the cellvalue appears in the crosstabulation table.

Both this attribute and the TABLES statement option for the cellvalue control the presence of the cellvalue in the table. For example, the expected cell frequency is present only when the EXPECTED option is used and the Expected cellvalue template has PRINT=ON specified.


CELLSTYLE AS Statement


Sets the style element of the cells in the column according to the values of the variables. Use this statement to set the presentation characteristics (such as foreground color, font face, and flyover) of individual cells in all destinations except the LISTING destinations.
Featured in: Creating a Customized Crosstabulation Table Template with No Legend

CELLSTYLE expression-1 AS <style-element-name><[style-attribute-specification(s)] ><..., expression-n AS <style-element-name><[style-attribute-specification(s)]>>;

Required Arguments

expression

is an expression that is evaluated for each cell. If expression resolves to TRUE (a non-zero 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:

1

is a fixed value that you can use to set a constant style element.

Example: These statements set the cellvalue Frequency background to gray:
define cellvalue Frequency;
	   other-statements ...;
   cellstyle 1 as {backgroundcolor=gray};
end;
_VAL_

is the value of the current cell.

Example: The following statements change the foreground color of the cellvalue Percent depending on its magnitude:
define cellvalue Percent;
   other-statements ...;
   cellstyle _val_ > 75.00 as {color=red},
      _val_ > 50.00 as {color=orange},
      _val_ > 25.00 as {color=green}; 
end;
comparison-operator

compares a variable with a value or with another variable.

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.

Options

Note:   Neither style-attribute-specification nor style-element-name is required. However, you must use at least one of them.  [cautionend]

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 on the style attributes that you can set in a column template, see Style Attributes and Their Values.
Default: If you do not specify any style attributes to modify, ODS uses the unmodified style-element-name.
style-element-name

is the name of the style element that displays 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 by using PROC TEMPLATE (see DEFINE STYLE Statement). By default, ODS displays different parts of ODS output with different style elements. For example, by default, the data in a column is displayed with the style element Data. The style elements that you would probably use with the CELLSTYLE AS statement in a column template are the following.

  • Data

  • DataFixed

  • DataEmpty

  • DataEmphasis

  • DataEmphasisFixed

  • DataStrong

  • DataStrongFixed

The style element provides the basis for displaying the column. Additional style attributes that you provide can modify the display.

Default: Data
See also: Viewing the Contents of a Style
See also: Working with Styles

DYNAMIC Statement


Defines a symbol that references a value that the data component supplies from the procedure or DATA step.
Tip: A dynamic variable that is defined in a template is available to that template and all the templates that it contains.

DYNAMIC dynamic-variable(s) ;

Required Arguments

dynamic- variable(s)

is a variable that is defined by SAS in the crosstabulation template. After a dynamic variable has been defined, you can use it in the TEXT statement within a footer or header template.

FMISSING

is the number of missing values in the table.

Requirement: The FMISSING dynamic variable must be specified by the DYNAMIC statement before you can use the dynamic variable in an expression.
NOTITLE

is set to 1 if the PROC FREQ's NOTITLE option was used, and it is set to 0 if the NOTITLE option was not used.

Requirement: The NOTITLE dynamic variable must be specified by the DYNAMIC statement before you can use the dynamic variable in an expression.
SAMPLESIZE

is set to 0 if the table is empty. Otherwise, it is set to 1.

Requirement: The SAMPLESIZE dynamic variable must be specified by the DYNAMIC statement before you can use the dynamic variable in an expression.
STRATNUM

is the current stratum number if the table has multiple strata. If the table has only one stratum, then the value is 0.

Requirement: The STRATNUM dynamic variable must be specified by the DYNAMIC statement before you can use the dynamic variable in an expression.
Featured in: Creating a Customized Crosstabulation Table Template with No Legend
STRATAVARIABLENAMES

is a string that identifies the current stratum by the name of the stratum variables.

var-1=value-1<var-n=value-n>
var-1-var-n

specifies the stratum variables.

value-1-value-n

specifies the values of the stratum variables.

Tip: The value is undefined if the table has only one stratum.
Requirement: The DYNAMIC statement must specify the STRATAVARIABLELABELS dynamic variables before the dynamic variables can be used in an expression.
STRATAVARIABLELABELS

is a string that identifies the current stratum by the label of the stratum variables.

var-1=value-1<var-n=value-n>
var-1-var-n

specifies the stratum variables.

value-1-value-n

specifies the values of the stratum variables.

Tip: The value is undefined when the table has only one stratum.
Requirement: The DYNAMIC statement must specify the STRATAVARIABLELABELS dynamic variables before you can use the dynamic variables in an expression.
Featured in: Creating a Customized Crosstabulation Table Template with No Legend and Creating a Crosstabulation Table Template with a Customized Legend

NOTES Statement


Provides information about the template.
Tip: The NOTES statement becomes part of the compiled template, which you can view with the SOURCE statement. SAS comments do not become part of the template.

NOTES 'text';

Required Arguments

'text'

provides information about the template.


END Statement


Ends the cellvalue template.
END;

Previous Page | Next Page | Top of Page