![]() | ![]() | ![]() | ![]() | ![]() |
This example shows you how to enhance SAS code to process PROC TABULATE output and format the results in an HTML table that is ready to display on the Web. To show some of what the HTML Tabulate Formatter can do, this example starts with a basic SAS program that does not include Tabulate Formatter code. Then, it describes how to perform the following enhancements to the SAS program:
You can look at the basic SAS program and the resulting output, which contains no HTML formatting.
Note: This example uses the Tabulate Formatter in batch mode. You can also use the formatter in interactive mode. For more information, see the overview information for the Tabulate Formatter.
The simplest way to add HTML formatting to your PROC TABULATE output is to embed 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 is valid on a wider range of Web browsers. The Tabulate Formatter lets you override these defaults easily to create customized HTML-enhanced output. (In this example, the default table alignment and font size are changed.)
For this example, two sections of code are added to the example program to do the following:
To format the output using the default properties, insert the following code after the TITLE statement:
%tab2htm(capture=on,
runmode=b);
The following arguments were specified in this code:
CAPTURE=ON, which turns 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, which specifies that you are running this program in batch mode. Although this argument is not required, you should include it to avoid confusion.
This example also sets some SAS sytem options so that the output is optimized for use on the Web. See Setting SAS System Options for information about the options you should set before capturing output using the Tabulate Formatter.
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. Leave the original SAS code unchanged after marking the start of the capture, and then add 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);
The following arguments were specified in this code:
CAPTURE=OFF, which turns capture mode off and stops the capturing process. All output generated between the on and off statements is converted into HTML. This argument is required.
RUNMODE=B, which 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, which 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, which 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, which specifies the text that appears as the title in the Web browser window title bar.
CENTER=Y, which 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, which 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 Web browser-specific. This argument overrides the font size setting in the property list.
Look at the modified example code and the resulting HTML file. The default formatting instructions defined by the default properties appear in bold. (To review definitions of code arguments, see Tabulate Formatter: Macro Syntax Reference.)
For the second enhancement, the colors of some elements in the output are changed.
You can use one of the following methods to customize your output:
When you call the Tabulate Formatter macro from your SAS program, supply the appropriate arguments that change the properties.
Create a customized property list and reference that list when capturing output. For information about creating a custom set of properties, see Customizing Properties.
To create the second enhancement, arguments are added to the Tabulate Formatter macro call. For this enhancement, custom formatting is added to the PROC TABULATE output by overriding some default properties and changing the color of the output. (Customizing with color makes the output easy to see and is valid in most Web browsers. You could choose to override any property settings.)
Look at the customized output before reviewing the changes. In addition, look at the modified example code.
Immediately after PROC TABULATE, the following block of code was modified to mark the end of the capture and specify the custom colors that will be used in the HTML output. This code specifies that the table displays as 90 percent of the Web 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);
The following arguments appeared in bold in this code:
CLCOLOR=BLUE, which specifies that the color of the table column labels should be blue. This argument overrides the setting for column label color in the property list.
RLCOLOR=BLUE, which specifies that the color of the table row labels should be blue. This argument overrides the setting for row label color in the property list.
TWIDTH=90, which 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 the customized output to ensure that the changes appear in the HTML file as specified. If you cannot see the color changes, your Web 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.
In the next enhancement, add the following items:
Take a look at the customized output first before reviewing the changes. In addition, look at the modified example code.
Immediately after PROC TABULATE, the following block of code was modified to mark the end of the capture and specify the background image that will be used in the 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);
The following arguments appeared in bold in this code:
BGTYPE=IMAGE, which specifies that the type of background for your Web page will be an image.
BG=MARBLE1.JPG, which specifies the name and location of the image that will be used as the background.
ENCODE=N, which specifies that the Tabulate Formatter will not replace angle brackets with the appropriate ASCII character representation. Setting ENCODE=N ensures that the Tabulate Formatter passes the brackets to the Web browser (where the Web browser will attempt to act on them as an HTML-formatting instruction).
An animated .GIF is included at the top of the page. The following statement produces 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 the customized output to ensure that the changes appear in the HTML file as specified.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Basic SAS code
Code for Enhancement 1
Code for Enhancement 2
Code for Enhancement 3
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
| Type: | Sample |
| Topic: | Software Components ==> HTML Formatting Tools |
| Date Modified: | 2006-12-08 03:04:53 |
| Date Created: | 2006-07-31 16:25:57 |
| Product Family | Product | Host | SAS Release | |
| Starting | Ending | |||
| SAS System | SAS/IntrNet | All | n/a | n/a |





