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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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