The SAS Output Delivery System and reporting techniques

How do you make row styles win over column styles in TABULATE?

Reply
SAS Employee
Posts: 174

How do you make row styles win over column styles in TABULATE?

Have you ever had a TABULATE report with both row and column styles, and been frustrated because the column styles take precedence over the row styles? In SAS 9.0 and prior versions, TABULATE's precedence rules cannot be overridden. Column precedence wins over row precedence, and row precedence wins over page precedence. If both row and column styles have been specified for a cell, the column style always wins.

In the following example, the data cells have a green foreground, because that's what the column style dictates:
[pre]
data sales;
input Region $ CitySize $ Population Product $ SaleType $
Units NetSales;
cards;
NC S 25000 A100 R 150 3750.00
NC M 125000 A100 R 350 8750.00
NC L 837000 A100 R 800 20000.00
NC S 25000 A100 W 150 3000.00
NC M 125000 A100 W 350 7000.00
NC L 625000 A100 W 750 15000.00
TX M 227000 A100 W 350 7250.00
TX L 5000 A100 W 750 5000.00
;


ods html file="tab.html";
proc tabulate data=sales format=dollar10.;
class product region saletype;
var netsales;
label netsales="Net Sales";
keylabel all="Total";
table product*{style={foreground=red}},
region*{style={foreground=yellow}},
saletype*{style={foreground=green}};
run;
ods html close;
[/pre]
But what if you wanted the row style to prevail, i.e. for the data cells to have a yellow foreground? In SAS 9.1, you can specify the STYLE_PRECEDENCE option on the TABLE statement. STYLE_PRECEDENCE accepts one of the values page, row, or column, where the value indicates which dimension's style should win. By default style precedence is column.

This shows how to modify the TABLE statement from the preceding example to force row style precedence:
[pre]
table product*{style={background=red}},
region*{style={background=yellow}},
saletype*{style={background=blue}}
/ style_precedence=row;
[/pre]
By the way, TABULATE has a TABLE statement option called FORMAT_PRECEDENCE that works in a similar way, but with formats rather than styles.

-- David Kelley, SAS


Message was edited by: David@SAS at Mar 10, 2006 2:06 PM
Message was edited by: David@SAS at Mar 10, 2006 2:08 PM
Ask a Question
Discussion stats
  • 0 replies
  • 221 views
  • 0 likes
  • 1 in conversation