SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Enhancing HTML Tabular Reports
Lesson Summary

This page contains


I. Text Summary

To go to the page where a task, programming feature, or concept was presented, select a link.


Applying the STYLE= Option
Use the STYLE= option within PROC TABULATE to control the display of table elements. The STYLE= option lets you specify cell background colors, text size and color, insert images, and add flyover text.

Changing Class Headings
To alter class headings in your table, follow the CLASS statement with a slash (/) and add the STYLE= option. Specify colors by supplying a SAS/GRAPH color name or an RGB color value in the form cxRRGGBB, where red, green, and blue range from 00 to FF.

Changing Keyword Headings
To alter keyword heading cells, add a KEYWORD statement to your program, followed by a slash (/) and the STYLE= option.

Changing the Box Cell
To alter the empty cell in the table's top-left corner, add a slash (/) and the BOX= option to your program's TABLE statement. Set the BOX= option equal to a STYLE= expression.

Changing Class Level Headings
To alter class level headings add a CLASSLEV statement to your program. Then add a slash (/) and the STYLE= option.

Using Formats as Option Values
To apply different styles to different class level headings, create a format to set attribute values. Use the new format as a value in the STYLE= option that follows the CLASSLEV statement.

Inheriting Style Attributes
To change headings for analysis variables, specify the STYLE= option in the VAR statement. To change only specified headings, use separate VAR statements for different style specifications. Use <parent> as the argument of the STYLE= option to specify that cells inherit the style attributes of the parent cell. The child cells will acquire all attributes.

Changing Styles for Data Cells
To specify the style of data cells, add the STYLE= option to the PROC TABULATE statement.

Applying Styles to Specific Cell Values
To control the appearance of a specific variable's values, attach the STYLE= option to the variable name in the TABLE statement. Enclose the option in braces { } and attach it to the variable with an asterisk (*).

Altering the Appearance of Text
You can use the following text-related STYLE attributes in combination with each other.

Attribute Sample Values
foreground white, cx336699
font_face times, helv, courier, serif
font_size 1-7, 10pt, 0.2in
font_style roman, italic, slant
font_weight light, medium, bold, black
font_width compressed, narrow, normal, wide

Adding Cell Traffic-Lighting
You can draw attention to data by making cells change in accordance with their values. To create cell traffic-lighting, start by creating a format to set background colors. Then apply the STYLE= option to the variable, setting the background attribute equal to your user-defined format.

Adding Flyover Text
Cell traffic-lighting draws attention to values and helps to explain their importance. Add flyover text by creating a format that repeats the ranges used for cell traffic-lighting. Supply a brief text string for the ranges and include a blank string for other. Then add the flyover attribute to the same STYLE= option that applies traffic-lighting and specify the new format as the value of flyover.

Passing HTML Tags
You can also enhance table output by passing HTML tags to SAS statements that use quoted text. Just insert the approriate tags as needed, supplying attributes and values and observing standard HTML syntax.

Embedding Images
Insert images in table cells by including IMG tags in text strings of your TABULATE program. To have text and images appear correctly together, mixed text and IMG strings must be enclosed in DIV tags.


II. Syntax

To go to the page where a statement or option was presented, select a link.

STYLE=<style-name> <<parent>> {attribute-1=value <...attribute-n=value>}

KEYWORD keyword(s) / STYLE={attribute-1=value <...attribute-n=value>}

BOX={STYLE={attribute-1=value <...attribute-n=value>}}

CLASSLEV variable(s) / STYLE={attribute-1=value <...attribute-n=value>}


III. Sample Program

The lesson's sample program is shown below. If you want to create this table, be sure to copy denmark.gif, germany.gif, uk.gif, and france.gif to the location where laguard.html is stored.

     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'='<DIV>Copenhagen<P><IMG src="denmark.gif"></DIV>'
                       'FRA'='<DIV>Frankfurt<P><IMG src="germany.gif"></DIV>'
                       'LON'='<DIV>London<P><IMG src="uk.gif"></DIV>'
                       'PAR'='<DIV>Paris<P><IMG src="france.gif"></DIV>';
        value $desback 'CPH'='cxBBDDCC'
                       'FRA'='cxAACCBB'
                       'LON'='cx99BBAA'
                       'PAR'='cx88AA99';
        value deplback low-105='lipk'
                       245-250='vpapb'
                       other='ywh';
        value deplflyo low-105='LOW traffic. Cut flights?'
                       245-250='HIGH traffic. Add flights?'
                       other=' ';
     run;
     proc tabulate data=flights.laguardia format=comma9.
          style={background=ywh};
        class dest / style={background=cxCCEEDD font_style=italic};
        classlev dest / style={background=$desback.};
        var boarded transferred deplaned / style={background=cxCCEEDD};
        var revenue / style=<parent>{foreground=black};
        table dest*(boarded transferred
              deplaned*{style={background=deplback. flyover=deplflyo.}}
              revenue*{style=<parent>}),min max mean sum /
              box={style={background=cxCCEEDD}};
        keyword min max mean sum /
                style={background=cxCCEEDD font_style=italic};
        label dest='Destination';
        format dest $desname.;
     run;
     ods html close;
     ods listing;


IV. Points to Remember

  • The keyword STYLE can be shortened to S in your programs: s={background=blue}.

  • STYLE expressions can be encosed in either curly { } or square [ ] braces.

  • Use restraint when adding color to tables. Excessive color is distracting and makes it difficult for readers to study your data.

  • When creating a user-defined format for traffic-lighting or flyovers, be sure to include a value for other.

  • Since traffic-lighting and flyovers are natural complements, consider adding them as a pair to your TABULATE code.

  • If a program text string is enclosed in single quotes (' '), enclose HTML values in double quotes (" ") to avoid early string termination. Likewise, if a text string is enclosed in double quotes (" "), enclose HTML values in single quotes (' ').

  • HTML is passed through without error correction. Bad mark-up can produce unexpected results when a browser displays your output.


  back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement