TEMPLATE Procedure: Creating Crosstabulation Table Templates |
Working with the CrossTabFreqs Crosstabulation Table Template |
When creating your own crosstabulation table template, you always define the new table with the same name as the existing table, which is Base.Freq.CrossTabFreqs. By default, the existing crosstabulation table that PROC FREQ creates is stored in the SASHELP.TMPLMST template store.
With PROC TEMPLATE, you can create a modified version of Base.Freq.CrossTabFreqs that you can save in a different template store by using the ODS PATH statement. All crosstabulation templates must have the same name. If you want to have multiple crosstabulation templates, put each one in a different template store. Then you can use the ODS PATH statement to add the template store that contains the version of the crosstabulation template you want to use.
For example, suppose that you have a crosstabulation template in the template store Corporat.Template and another crosstabulation template in Govment.Templat. In the following code, the first ODS PATH statement adds the template store Corporat.Templat. The first PROC FREQ code is then formatted using the crosstabulation table template from Corporat.Templat. The second ODS PATH statement removes Corporat.Templat, and the third ODS PATH statement adds Govment.Templat. The last PROC FREQ step then uses the crosstabulation template from Corporat.Templat.
ods path(prepend) corporat.templat(read); ... proc freq code ... ods path(remove) corporat.templat; ods path(prepend) govment.templat; ... proc freq code ...
For more information about the ODS PATH statement, see ODS PATH Statement.
What Makes the Crosstabulation Table Unique? |
Crosstabulation tables produced by PROC FREQ are different from other tables that SAS produces. Most other tables are composed of rows and columns with one value for each row-column combination. However, the crosstabulation table has these distinctive characteristics:
The crosstabulation table can have up to nine values for each row-column combination, depending on the options specified by the TABLES statement. Most other tables that SAS creates have only one value for each row-column combination.
Crosstabulation tables have a separate box, which is called a legend, to contain the labels for the cellvalues. No other table that SAS produces has a legend.
The far left column contains the row variable values. Each value in this column provides a label for the row in the same way that the column variable values provide labels for the columns.
Each value in these headers provides a label for the columns of the table.
The far right column contains the row totals. The bottom row contains the column totals.
The grand total cell is the last cell of the row and column totals.
Comparison Between Table Templates and Crosstabulation Table Templates |
Because the crosstabulation table is unique, the syntax used to create crosstabulation templates differs significantly from other table templates.
The crosstabulation template has no parent template, and it cannot serve as a parent to another template.
Most of the attributes, such as CENTER and PANELS=, that are defined for classic table templates are not defined in the crosstabulation table template.
Crosstabulation table templates use DEFINE CELLVALUE blocks instead of the DEFINE COLUMN blocks that are used in other table templates.
Crosstabulation table templates use the CELLVALUE statement instead of the COLUMN statement that is used in other table templates.
Both crosstabulation table templates and other table templates use DEFINE HEADER and DEFINE FOOTER blocks. However, the attributes that can be used in each of these blocks differ.
DEFINE HEADER and DEFINE FOOTER blocks can contain multiple TEXT statements only in crosstabulation table templates. ODS then chooses which TEXT statement to use at execution time.
A TEXT statement can specify a WHERE expression only in crosstabulation table templates. ODS uses the WHERE expression to determine whether to use (the TEXT statement) text as the header text.
The CELL_STYLE, COLS_HEADER, COL_TOTAL_STYLE, COL_VAR_STYLE, GRAND_TOTAL_STYLE, LEGEND_STYLE, ROWS_HEADER, and ROW_VAR_STYLE attributes are unique to the crosstabulation table.
The ROWS_HEADER and COLS_HEADER attributes are unique to the crosstabulation table.
The NVAR, MVAR, and TRANSLATE-INTO statements are not supported for crosstabulation templates.
Crosstabulation Table Regions and Corresponding Attributes |
When creating a crosstabulation template, you can use attributes to modify individual table regions. The following figure and corresponding table identify the different parts of the crosstabulation table and the attributes that control the style of each part.
Crosstabulation Table Regions That Can Be Modified
Most regions use DEFINE CROSSTABS style attributes to specify a style. The following table show the style attribute that effects each table region. For complete documentation on DEFINE CROSSTABS attributes, see DEFINE CROSSTABS Attributes. Headers and footers use the STYLE= attribute that is valid for the DEFINE HEADER and DEFINE FOOTER statements. For information on the STYLE= attribute, see DEFINE HEADER and DEFINE FOOTER Attribute Statements.
Item | Crosstabulation Table Region |
Style Attribute |
---|---|---|
Legend | LEGEND_STYLE= | |
Row variable name | ROWS_HEADER= | |
Row variable value | ROW_VAR_STYLE= | |
Data cell | CELL_STYLE= | |
Column total | COL_TOTAL_STYLE= | |
Footer | STYLE= | |
Grand total | GRAND_TOTAL_STYLE= | |
Row total | ROW_TOTAL_STYLE | |
Column variable name | COLS_HEADER= | |
Header | STYLE= | |
Column variable value | COL_VAR_STYLE= |
Copyright © 2008 by SAS Institute Inc., Cary, NC, USA. All rights reserved.