TABULATE Procedure

Example 15: Style Precedence

Features:

PROC TABULATE statement options: FORMAT=

STYLE= option:
CLASSLEV statement
TABLE statement
TABLE statement:
crossing (*) operator
STYLE_PRECEDENCE= option
Other features:

ODS HTML statement

FORMAT statement

Data set: SALES

Details

This example does the following:
  • creates a category for each sales type, retail or wholesale, in each region
  • applies the dollar format to all cells in the table
  • applies an italic font style for each region and sales type
  • applies a style (background = red, yellow, or orange) color based on the STYLE_PRECEDENCE = option
  • generates ODS HTML output

Program

proc format;
      value $saletypefmt 'R'='Retail'
                        'W'='WholeSale';
run;
ods html file="stylePrecedence.html";
title "Style Precedence";
title2 "First Table: no precedence, Orange";
title3 "Second Table: style_precedence=page, Red";
proc tabulate data=sales format=dollar10.;
class product region saletype;
   
classlev region saletype / style={font_style=italic};
   
var netsales;
label netsales="Net Sales";
   
keylabel all="Total";
   
table product *{style={background=red}},
region*{style={background=yellow}},
saletype*{style={background=orange}};
table product *{style={background=red}},
region*{style={background=yellow}},
saletype*{style={background=orange}} / style_precedence=page;
format saletype $saletypefmt.;
   
run;
   

Program Description

Create the SALETYPEFMT. formats.PROC FORMAT creates formats for SALETYPE.
proc format;
      value $saletypefmt 'R'='Retail'
                        'W'='WholeSale';
run;
Specify the ODS output filename.The ODS HTML statement produces output that is written in HTML.
ods html file="stylePrecedence.html";
Specify the titles of the tables to be produced.Two tables will be generated. The First Table will show no style precedence whereas the Second Table will show that the color that takes precedence is based on what is specified by the STYLE_PRECEDENCE option.
title "Style Precedence";
title2 "First Table: no precedence, Orange";
title3 "Second Table: style_precedence=page, Red";
Specify the table options.The FORMAT= option specifies DOLLAR10. as the default format for the value in each table cell.
proc tabulate data=sales format=dollar10.;
Specify subgroups for the analysis.The CLASS statement separates the analysis by values of Product, Region, and SaleType.
class product region saletype;
   
Specify styles for the subgroups.The CLASSLEV statement specifies a style for the Region and Saletype elements.
classlev region saletype / style={font_style=italic};
   
Specify the analysis variable.The VAR statement specifies that PROC TABULATE calculate statistics on the Netsales variable.
var netsales;
Specify labels.The LABEL statement renames the Netsales variable to Net Sales.
label netsales="Net Sales";
   
Specify Keylabel.The KEYLABEL statement labels the universal class variable ALL to Total.
keylabel all="Total";
   
Define the table rows and columns.The TABLE statement creates a table per product per page. In this example there is one product, A100. The TABLE statement also creates a row for each formatted value of Region and creates a column for each formatted value of SaleType. Each cell that is created by these rows and columns contains the sum of the analysis variable Net Sales for all observations that contribute to that cell. The STYLE= option in the dimension expression overrides any other STYLE= specifications in PROC TABULATE that specify attributes for the table cells. In this first table, the column expression is the default and the style associated with column takes precedence. Therefore, orange will be the default color of the background.
table product *{style={background=red}},
region*{style={background=yellow}},
saletype*{style={background=orange}};
Define the table rows and columns using the STYLE_PRECEDENCE option.The TABLE statement creates a table per product per page, A100. The TABLE statement also creates a row for each formatted value of Region and creates a column for each formatted value of SaleType. Each cell that is created by these rows and columns contains the sum of the analysis variable Net Sales for all observations that contribute to that cell. The STYLE= option in the dimension expression overrides any other STYLE= specifications in PROC TABULATE that specify attributes for the table cells. In this second table, the STYLE_PRECEDENCE option is specified on the page expression. Therefore, the style that applies to the background is red.
table product *{style={background=red}},
region*{style={background=yellow}},
saletype*{style={background=orange}} / style_precedence=page;
Format the output.The FORMAT statement assigns formats to the SaleType variable.
format saletype $saletypefmt.;
   
Run the program.
run;
   

Output

Style Precedence
Style Precedence