![]() | ![]() | ![]() | ![]() | ![]() |
This example shows how the Output Formatter can help you put SAS output on the Web. To show some of what the HTML Output Formatter can do, this example starts with a SAS program that does not include Output Formatter code. Then, it describes how to perform the following two enhancements to the SAS program:
This example uses PROC MORTGAGE to provide summary mortgage and annual payment information.
You can look at the basic SAS program and the resulting output, which contains no HTML formatting.
Note: This example uses the Output Formatter in batch mode. You can also use the Output Formatter in interactive mode. For more information, see Capturing SAS Output.
The simplest way to add HTML formatting to your procedure output is to embed Output Formatter macro calls into the SAS program and use the Output 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.
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 OPTIONS statement:
%out2htm(capture=on,
window=output,
runmode=b);
You can specify the following arguments:
CAPTURE=ON, which turns capture mode on for the Output Formatter. This tells the macro that you want to capture everything written to the specified window until capture mode is turned off. You must specify this argument to start capturing output.
WINDOW=OUTPUT, which indicates that you want to capture all of the information written to the SAS Output window. This argument is required when you turn capture mode on or off.
RUNMODE=B, which specifies that you are running this program in batch mode.
Every time you turn capturing on, you must include a corresponding CAPTURE=OFF statement. When you mark the end of the capture, the Output Formatter creates the HTML file. Leave the original SAS code unchanged after marking the start of the capture, and then add the following code to the end of the file:
%out2htm(htmlfile=myfile.html
capture=off,
window=output,
openmode=replace,
runmode=b);
You can specify the following arguments:
HTMLFILE=MYFILE.HTML, which specifies the file to which the HTML-formatted results are written. This argument is required when you turn capture mode off. You must include a fully qualified path and filename.
CAPTURE=OFF, which turns capture mode off and stops the capturing process. Everything that was captured is converted into HTML. This argument is required.
WINDOW=OUTPUT, which indicates that you want to capture all of the information written to the SAS Output window. This argument is required when you turn capture mode on or off.
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.
RUNMODE=B, which specifies that you are running this program in batch mode.
Code and Resulting HTML File
This is what the modified example code looks like. This is the resulting HTML file. The default formatting instructions defined by the default properties appear in bold. (To review definitions of code arguments, see Output Formatter: Macro Syntax Reference.)
You can override the default properties and create customized HTML-enhanced output. 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:
The second enhancement adds arguments to the Output Formatter macro call. For information about creating a custom set of properties, see Customizing Properties.
For this enhancement, custom formatting is added to the PROC MORTGAGE 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.)
Make the following changes:
Note: For every CAPTURE=ON statement, you must include a matching CAPTURE=OFF statement, and you must match the on/off statements for the type of window you are capturing (log or output). For example, if you turn capturing on to capture the log window, you must also turn capturing off for the log window.
Look at the customized output before reviewing the changes. In addition, look at the modified example code, which contains comment lines that explain the modifications.
To mark the start of what you want to capture in the first segment, use what was inserted from the previous modification after the OPTIONS statement:
%out2htm (capture=on,
window=output,
runmode=b);
Immediately after PROC MORTGAGE, add the following block of code to mark the end of the first segment and specify the custom colors that will be used in the HTML output. The items that differ from the first enhancement are denoted in bold.
%out2htm(htmlfile=myfile.html,
capture=off,
window=output,
openmode=replace,
pagepart=head,
runmode=b,
tcolor=red,
hcolor=blue);
The following arguments appeared in bold in this code:
PAGEPART=HEAD, which indicates that you want to include only the HTML headers in the resulting HTML file. (Footers will be added later with the PAGEPART=FOOT argument.)
TCOLOR=RED, which specifies that the color of the SAS title lines should be red. This argument overrides the setting for title color in the property list.
HCOLOR=BLUE, which specifies that the color of the SAS header lines should be blue. This argument overrides the setting for header color in the property list.
The output from PROC MORTGAGE is written to the specified file and the necessary HTML tags are included so that the colors are used as indicated in your SAS macro call.
The code modification described previously specified custom colors for some output components and then stopped the Output Formatter from capturing the remaining procedure output. Capturing had to be turned back on to capture the output produced by the rest of the SAS program. If capturing had not been turned back on, the output generated by the remainder of the example code would not be included in the HTML file. To capture the rest of the output, add the following block of code, which is the same as the code used earlier to start capturing output:
%out2htm(capture=on,
window=output,
runmode=b);
Whenever you turn capturing on within your SAS program, you must also turn it off. The following code marks the end of capturing and includes some arguments that override the default properties:
%out2htm(htmlfile=myfile.html,
capture=off,
window=output,
openmode=append,
pagepart=foot,
runmode=b,
tcolor=yellow,
fcolor=#ffffff,
hcolor=teal);
The following arguments appeared in bold in this code:
OPENMODE=APPEND, which indicates that you want these results to appear after the previous results in the specified file, rather than override the previous results. This argument is required when you turn capture mode off.
PAGEPART=FOOT, which indicates that you want to include only the HTML footers in the resulting HTML file. (The headers were written to the file with the first macro call, using the PAGEPART=HEAD argument.)
TCOLOR=YELLOW, which specifies that the color of the SAS title lines should be yellow. This argument overrides the setting for title line color in the property list.
FCOLOR=#FFFFFF, which specifies that the color of the SAS footnote lines should be white. This argument overrides the setting for footnote line color in the property list.
HCOLOR=TEAL, which specifies that the color of the SAS header lines should be teal. This argument overrides the setting for header line color in the property list.
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.
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
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: | 2007-10-15 07:21:20 |
| Date Created: | 2006-07-31 15:35:02 |
| Product Family | Product | Host | SAS Release | |
| Starting | Ending | |||
| SAS System | SAS/IntrNet | All | n/a | n/a |





