![]() | ![]() | ![]() | ![]() | ![]() |
This example shows you how to start using the Data Set Formatter and how to produce HTML tables from your SAS data sets. Start with a basic SAS program that uses
The resulting output from the program does not contain any HTML formatting. However, the remainder of this example explains how to incorporate HTML formatting by making the following enhancements to the existing SAS program:
Note: This example uses the Data Set Formatter in batch mode.
You can quickly produce HTML-formatted tables by adding the Data Set Formatting macro invocation to the original SAS program. The changes made to the SAS program include the following:
replacing the PROC SQL code with the first macro call, adding a table caption, and adding a WHERE clause to retrieve only 1996 data.
replacing the PROC PRINT code with a second macro call, which includes the observation number column, totals some columns, adds a table caption, and retrieves data before the year 2000.
Look at the modified SAS program, which includes the Data Set Formatter enhancements, before reviewing the details about how the program was modified. (To review definitions of code arguments, see Data Set Formatter: Macro Syntax Reference.)
The data now appears in two HTML-formatted tables. Each of these tables also has a caption located just above the table. The HTML formatting instructions are governed by default properties provided with the Data Set Formatter.
Delete the following PROC SQL code from the SAS program:
*;
* Use SQL to print selected information;
*;
title 'PROC SQL Output';
footnote '(Data generated by PROC MORTGAGE)';
proc sql;
select *
from monthly
where year eq 1996;
quit;
Replace the deleted PROC SQL code with the following Data Set Formatter code, which creates an HTML table:
*;
* Create table instead of using PROC SQL.
*;
title 'Formerly PROC SQL Output';
footnote '(Data generated by PROC MORTGAGE)';
%ds2htm(htmlfile=myfile.html,
openmode=replace,
pagepart=head,
data=monthly,
where=year eq 1996,
caption=Information for 1996);
You can specify the following arguments:
HTMLFILE=MYFILE.HTML, which specifies the path and HTML file you want to create. Make sure you include the fully qualified path. You must specify this argument.
OPENMODE=REPLACE, which indicates that you want these results to replace or overwrite the contents of the specified file.
PAGEPART=HEAD, which indicates that you want it to include only the HTML headers in the resulting HTML file. (You will add the footers to this file later with the PAGEPART=FOOT argument.)
DATA=MONTHLY, which indicates the name of the SAS data set you want to format using the Data Set Formatter.
WHERE=YEAR EQ 1996, which retrieves only the data that is associated with 1996. Using this SAS WHERE clause subsets your data based on the criteria you supply.
CAPTION=INFORMATION FOR 1996, which provides text for the table caption.
Delete the following PROC PRINT code from the end of the SAS program, as follows:
title 'PROC PRINT Output'; footnote '(Data generated by PROC MORTGAGE)'; proc print data=monthly noobs label; where year lt 2000; var year month begpri payment int repay endpri; sum payment int repay; run;
Replace the deleted PROC PRINT code with the following Data Set Formatter code, which creates the second HTML table. It also provides sums for three columns and adds a table caption.
*;
* Create table instead of using PROC PRINT.
*;
title 'Formerly PROC PRINT Output';
footnote '(Data generated by PROC MORTGAGE)';
%ds2htm(htmlfile=myfile.html,
openmode=append,
pagepart=foot,
data=monthly,
obsnum=y,
where=year lt 2000,
var=year month begpri payment int repay endpri,
sum=payment int repay,
caption=Information prior to the year 2000.gif);
You can specify the following arguments:
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.)
OBSUM=Y, which includes the observation numbers in the table.
WHERE=YEAR LT 2000, which retrieves only the data that is associated with years less than 2000. Using this SAS WHERE clause subsets your data based on the criteria you supply.
VAR=YEAR MONTH BEGPRI PAYMENT INT REPAY ENDPRI, which specifies which variables should appear in the output and in which order.
SUM=PAYMENT INT REPAY, which specifies the three variables for which you want a total.
CAPTION=INFORMATION PRIOR TO THE YEAR 2000, which provides text for the table caption.
The second enhancement overrides some of the default properties. These properties control the colors used for some table elements and the size of the caption text. To provide these formatting instructions, make the following changes to your SAS program:
Add arguments to the first macro call. These arguments change the following properties in the first table:
tbbgcolr) to whitectext) to blueclbgcolr) to gray.Add arguments to the second macro call. These arguments change the following properties in the second table:
tbbgcolr) to whitectext) to blueclbgcolr) to grayobgcolr) to grayscolor) to redccolor) to blackcsize) size.You might find it helpful to look at the finished SAS program, which includes the second set of Data Set Formatter enhancements.
Take a look at the resulting HTML file. All text is blue, including titles and footnotes. The two HTML-formatted tables appear with blue text and a white background. The caption for the second table appears in a larger font and the text is black. The custom formatting is accomplished by specifying macro arguments that override the default properties.
Modify the first data set macro invocation by adding the arguments that appear in bold in the following code:
%ds2htm(htmlfile=myfile.html,
openmode=replace,
pagepart=head,
tbbgcolr=white,
ctext=blue,
clbgcolr=#aaaaaa,
data=monthly,
where=year eq 1996,
caption=Information for 1996);
The following arguments appeared in bold in this code:
TBBGCOLR=WHITE, which sets the background color of the table to white.
CTEXT=BLUE, which sets the color of the text to blue.
CLBGCOLR=#AAAAAA, which sets the background color of the column labels to gray.
Modify the second Data Set Formatter macro invocation to include the arguments that appear in bold in the following code:
%ds2htm(htmlfile=myfile.html,
openmode=append,
pagepart=foot,
tbbgcolr=white,
ctext=blue,
clbgcolr=#aaaaaa,
obgcolr=#aaaaaa,
scolor=red,
csize=+2,
ccolor=black,
data=monthly,
obsnum=y,
where=year lt 2000,
var=year month begpri payment int repay endpri,
sum=payment int repay,
caption=Information prior to the year 2000);
The following arguments appeared in bold in this code:
TBBGCOLR=WHITE, which sets the background color of the table to white.
CTEXT=BLUE, which sets the color of the text to blue.
CLBGCOLR=#AAAAAA, which sets the background color of the column labels to gray.
OBGCOLR=#AAAAAA, which sets the background color of the column that contains observation numbers.
SCOLOR=RED, which sets the text color of the column sums to red.
CSIZE=+2, which increases the size of the caption font.
CCOLOR=BLACK, which sets the color of the caption to black.
For more information, see the following topics:
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:16:28 |
| Date Created: | 2006-07-28 16:32:17 |
| Product Family | Product | Host | SAS Release | |
| Starting | Ending | |||
| SAS System | SAS/IntrNet | All | n/a | n/a |




