Enhancing HTML Tabular Reports |
Adding Color to Table
Cells |
Using Formats as Option Values
You've seen how to add color to class level headings by combining the CLASSLEV statement with the STYLE= option. This approach applies a color to all of the levels. But what if you would like a different color to appear for each level of a class variable? For example, the Laguardia table has four destinations that could each show a different shade. To apply different colors, create a user-defined format.
As you know from the lesson Formatting Variable Values, you can apply user-defined formats to data values. For example, the first version of your TABULATE program formatted values to display the full name of flight destinations. |
ods listing close; ods html path='c:\data' body='laguard.html'; title1 'Laguardia Flights by Destination'; title2 'and Revenue, March 4-10'; proc format; value $desname 'CPH'='Copenhagen' 'FRA'='Frankfurt' 'LON'='London' 'PAR'='Paris'; run; proc tabulate data=flights.laguardia format=comma9.; class dest / style={background=cxCCEEDD}; var boarded transferred deplaned revenue; table dest*(boarded transferred deplaned revenue), min max mean sum / box={style={background=cxCCEEDD}}; keyword min max mean sum / style={background=cxCCEEDD}; label dest='Destination'; format dest $desname.; run; ods html close; ods listing; |
You can use a similar procedure to specify colors for the different
destinations:
|
value $desback 'CPH'='cxBBDDCC' 'FRA'='cxAACCBB' 'LON'='cx99BBAA' 'PAR'='cx88AA99'; |
|
classlev dest / style={background=$desback.}; |
Your program and its output are shown below. |
ods listing close; ods html path='c:\data' body='laguard.html'; title1 'Laguardia Flights by Destination'; title2 'and Revenue, March 4-10'; proc format; value $desname 'CPH'='Copenhagen' 'FRA'='Frankfurt' 'LON'='London' 'PAR'='Paris'; value $desback 'CPH'='cxBBDDCC' 'FRA'='cxAACCBB' 'LON'='cx99BBAA' 'PAR'='cx88AA99'; run; proc tabulate data=flights.laguardia format=comma9.; class dest / style={background=cxCCEEDD}; classlev dest / style={background=$desback.}; var boarded transferred deplaned revenue; table dest*(boarded transferred deplaned revenue), min max mean sum / box={style={background=cxCCEEDD}}; keyword min max mean sum / style={background=cxCCEEDD}; label dest='Destination'; format dest $desname.; run; ods html close; ods listing; |
Laguardia Flights by Destination |
and Revenue, March 4-10 |
Min | Max | Mean | Sum | ||
Destination | 81 | 154 | 131 | 786 | |
Copenhagen | Boarded | ||||
Transferred | 5 | 21 | 13 | 75 | |
Deplaned | 103 | 177 | 147 | 881 | |
Revenue | 109,885 | 196,540 | 139,951 | 839,705 | |
Frankfurt | Boarded | 129 | 210 | 170 | 1,190 |
Transferred | 5 | 22 | 13 | 91 | |
Deplaned | 147 | 237 | 188 | 1,314 | |
Revenue | 100,987 | 187,636 | 142,912 | 1,000,382 | |
London | Boarded | 151 | 241 | 188 | 3,760 |
Transferred | 4 | 18 | 11 | 227 | |
Deplaned | 114 | 250 | 199 | 3,987 | |
Revenue | 106,753 | 198,744 | 159,478 | 3,189,554 | |
Paris | Boarded | 146 | 182 | 161 | 2,089 |
Transferred | 7 | 29 | 16 | 204 | |
Deplaned | 153 | 227 | 183 | 2,378 | |
Revenue | 123,456 | 195,468 | 151,477 | 1,969,201 |
Use restraint when adding color to tables. Excessive color is distracting and makes it difficult for readers to study your data. The Laguardia table uses many colors, but this is just to demonstrate ODS HTML features. Notice that, to improve clarity, the five colors used so far are five graduated shades. |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.