Research and Development

HTML Tabulate Formatter: Usage Example

To show some of what the HTML Tabulate Formatter can do, we start with a SAS program that does not include Tabulate Formatter code. Then, we will describe how we performed the following enhancements to the SAS program:

The example shows how to use the Tabulate Formatter in batch mode, which lets you enter code directly into your SAS program. You can also work with the Tabulate Formatter interactively via windows. For information about working interactively, see Capturing Output Interactively. For an overview of the Tabulate Formatter, review the Overview page.

The SAS Program (used as a basis for the example)

The example uses PROC TABULATE to provide actual and predicted product sales across different geographical areas. This first example code shows our SAS program without any Tabulate Formatter macro calls. We submitted this code and saved the results to a file. The results output file displays as plain text and contains no HTML formatting.


Enhancement 1: Adding Tabulate Formatter Macro to the SAS Program

The easiest way to add HTML formatting to your PROC TABULATE output is to embed the Tabulate Formatter macro calls into the SAS program and use the Tabulate Formatter default properties. These properties provide HTML 2.0 tags as the default properties so that the formatting will be valid on a wider range of browsers. The Tabulate Formatter lets you override these defaults easily to create customized HTML-enhanced output. (In this example we changed the default table alignment and font size.)

For the example, we added two sections of code to the example program that do the following:

Marking the start of the capture

To format our output using the default properties, we inserted the following after the TITLE statement in our code:

   %tab2htm(capture=on,
            runmode=b);

where

capture=on
turns the capture mode on for the Tabulate Formatter. This tells the macro that you want to capture everything written to the Output window until capture mode is turned off. You must specify this argument to start capturing output.

runmode=b
specifies that you are running this program in batch mode. Although this argument is not required, you should include it to avoid confusion.

Note: We also added a FORMCHAR option in our PROC TABULATE statement to specify the formatting characters displayed in the output. Formatting characters are used to outline the tabular output. In order for the Tabulate Formatter to work, special form characters must be used. You can choose to either set the FORMCHAR system option or use the FORMCHAR option of PROC TABULATE. To see the code examples, see the discussion of FORMCHAR in Capturing Tabulate Output Interactively.

Marking the end of the capture

Every time you turn capturing on, you must include a corresponding capture off statement. When you mark the end of the capture, the Tabulate Formatter creates the HTML file. We left the original SAS code unchanged after marking the start of the capture, then added the following to the end of the file:

     %tab2htm(capture=off,
              runmode=b,
              openmode=replace,
              htmlfile=ex2.html,
              brtitle=Tabulate Formatter Example,
              center=Y,
              tsize=+3);

where

capture=off
turns capture mode off and stops the process of capturing. All output generated between the on and off statements is converted to HTML. This argument is required.

runmode=b
specifies that you are running this program in batch mode. Although this argument is not required, you should include it to avoid confusion.

openmode=replace
indicates that you want these results to replace or overwrite the contents of the specified file. This argument is required only when you want to override the default setting.

htmlfile=ex2.html
specifies the file to which your HTML-formatted results are written. This argument is required when you turn capture mode off. You must include a fully-qualified path and filename.

brtitle=Tabulate Formatter Example
specifies the text that appears as the title in the browser window title bar.

center=Y
specifies that all output generated by the current invocation of the macro is centered. This argument overrides the alignment setting in the property list.

tsize=+3
specifies the size of the font used to display SAS title lines. Valid values are N, +N, and -N, where N is an integer. Valid values for N are browser specific. This argument overrides the font size setting in the property list.

Before submitting the program, you must ensure that the Output window contains only output from the TABULATE procedure. If output from any SAS procedure other than TABULATE exists in the Output window, the Tabulate Formatter will fail. If necessary, clear the window before submitting the program.

Code and Resulting HTML File

Look at our modified example code and the resulting HTML file. Some parts of the output appear in a bold font. Remember, these are the default formatting instructions defined by the default properties. (To review definitions of code arguments, see Tabulate Formatter: Macro Syntax Reference.)


Enhancement 2: Changing Colors of Output Elements

For the second enhancement, we changed colors of some elements in the output.

You can use one of the following methods to customize your output:

To create our second enhancement, we added arguments to the Tabulate Formatter macro call. For this enhancement we added custom formatting to our PROC TABULATE output by overriding some default properties and changing the color of the output. (We chose to customize with color because it is easy to see and is valid in most browsers. You could choose to override any property settings.)

Code and Resulting HTML File

It might be easier to follow our changes if you look at the customized output before we discuss the changes. We have also provided our modified example code.

Specifying the Changes

Immediately after PROC TABULATE, we modified the following block of code to mark the end of the capture and specify the custom colors that will be used in our HTML output. We also specified that the table displays as 90 percent of the browser window. The items that differ from the previous enhancement are denoted in bold.

%tab2htm(capture=off,
         runmode=b,
         openmode=replace,
         htmlfile=ex3.html,
         brtitle=Tabulate Formatter Example,
         center=Y,
         tsize=+3,
         clcolor=blue,
         rlcolor=blue,
         twidth=90);

where

clcolor=blue
specifies that the color of the table column labels should be blue. This argument overrides the setting for column labels color in the property list.

rlcolor=blue
specifies that the color of the table row labels should be blue. This argument overrides the setting for row labels color in the property list.

twidth=90
specifies the width of the table. This argument overrides the setting for table width in the property list. The units for this value are determined by the TWUNITS argument, which is set to PERCENT in the default property list.

The output from PROC TABULATE is written to the specified file and the necessary HTML tags are included so that the colors and table width are used as indicated in your SAS macro call.

Take another look at our customized output to see that our changes do appear in the HTML file as we specified. If you cannot see the color changes that we made, it is because your browser does not support colored text. You can view the document source and see that the HTML tags to change the color are included in the file.


Enhancement 3: Adding Images

In the next enhancement, we added the following:

Code and Resulting HTML File

Take a look at the customized output first before we discuss the changes. We have also provided our modified example code.

Specifying the Changes

Immediately after PROC TABULATE we modified the following block of code to mark the end of the capture and specify the background image that will be used in our HTML output. The items that differ from the second enhancement are denoted in bold.

%tab2htm(capture=off,
         runmode=b,
         openmode=replace,
         htmlfile=final.html,
         brtitle=Tabulate Formatter Example,
         center=Y,
         tsize=+3,
         clcolor=blue,
         rlcolor=blue,
         twidth=90,
         bgtype=image,
         bg=marble1.jpg,
         encode=N);

where

bgtype=image
specifies that the type of background for your Web page will be an image.

bg=marble1.jpg
specifies name and location of the image that will be used as the background.

encode=N
specifies that the Tabulate Formatter will not replace angle brackets with the appropriate ASCII character representation. Setting encode=N ensures that the Tabulate Formatter will pass the brackets to the browser (where the browser will attempt to act on them as an HTML-formatting instruction).

We also included an animated .GIF at the top of the page. We included this statement to produce the image. Bold text denotes the changes.

title '<IMG ALIGN=CENTER SRC=globeanm.gif> World Wide Product Sales Report';

The output from PROC TABULATE is written to the specified file and the necessary HTML tags are included so that the images display.

Take another look at our customized output to see that our changes do appear in the HTML file as we specified.

These samples illustrate how you can enhance SAS code to process PROC TABULATE output and format the results in an HTML table ready for display on the Web. To review the Tabulate Formatter product documentation, return to the HTML Tabulate Formatter main page.


Return to the HTML Formatting Tools main page.