BookmarkSubscribeRSS Feed
David_SAS
SAS Employee

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:

 

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;


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:

 

table product*{style={background=red}}, 
region*{style={background=yellow}}, 
saletype*{style={background=blue}}
/ style_precedence=row;


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

1 REPLY 1
ChrisNZ
Tourmaline | Level 20

@David_SAS Changed the title to make it clear this is a "tip" rather than a question.

Hope you don't mind. Please change back if you think that's misguided. 🙂

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 7202 views
  • 2 likes
  • 2 in conversation