FORMAT Procedure

Example 14: Using a Format to Create a Drill-down Table

Features:

VALUE statement

Other features:

PROC PRINT FORMAT statement

Details

This example creates an HTML table that has population information about five U.S. states. The name of the state is a link to the state’s Web site. The link is created using a user-defined format to format the state name. This example does the following:
  • creates the data set that contains the state population information
  • creates a user-defined format using the VALUE statement, where the value is an HTML link (<a>) element
  • defines the name of the HTML file and the titles for the HTML file
  • prints the HTML table using the user-defined format

Program

data mydata;
   format population comma12.0;
   label st='State';
   label population='Population';
   input st $ 1-2 population;
   year=2000;
   datalines;
VA  7078515
NC  8049313
SC  4012012
GA  8186453
FL 15982378
;
run;
proc format;
value $COMPND
'VA'='<a href=http://www.va.gov>VA</a>'
'NC'='<a href=http://www.nc.gov>NC</a>'
'SC'='<a href=http://www.sc.gov>SC</a>'
'GA'='<a href=http://www.ga.gov>GA</a>'
'FL'='<a href=http://www.fl.gov>FL</a>';
run;
ods html file="c:\mySAS\html\Drilldown.htm" 
 (title="An ODS HTML Drill-down Table Using a User-defined Format in the PRINT
 Procedure");

title h=.25in "Year 2000 U.S. Census Population";
title2 color=gray "An ODS HTML Drill-down Table Using a User-defined Format in 
the PRINT Procedure";
footnote color=gray "(Click the underlined text to drill down.)";
options nodate;
proc print data=mydata label noobs;
 var st population;
 format st $compnd. ;
run;

ods html close;
ods html;

Program Description

Create the data set.The mydata DATA step creates a data set that contains information about five U.S. state populations based on the census taken in the year 2000. The variables that are created assign data for the year of the census, the state abbreviations, and the state population.
data mydata;
   format population comma12.0;
   label st='State';
   label population='Population';
   input st $ 1-2 population;
   year=2000;
   datalines;
VA  7078515
NC  8049313
SC  4012012
GA  8186453
FL 15982378
;
run;
Create the $COMPND. format.The $COMPND. format formats each state as a link to the state’s respective Web site.
proc format;
value $COMPND
'VA'='<a href=http://www.va.gov>VA</a>'
'NC'='<a href=http://www.nc.gov>NC</a>'
'SC'='<a href=http://www.sc.gov>SC</a>'
'GA'='<a href=http://www.ga.gov>GA</a>'
'FL'='<a href=http://www.fl.gov>FL</a>';
run;
Set up the table filename and table titles.The ODS HTML FILE= option names the directory and filename where SAS saves the HTML output.
ods html file="c:\mySAS\html\Drilldown.htm" 
 (title="An ODS HTML Drill-down Table Using a User-defined Format in the PRINT
 Procedure");

title h=.25in "Year 2000 U.S. Census Population";
title2 color=gray "An ODS HTML Drill-down Table Using a User-defined Format in 
the PRINT Procedure";
footnote color=gray "(Click the underlined text to drill down.)";
Print the table and close and reopen the HTML destination.The PRINT procedure uses the format $COMPND. to format the state name. The formatted name is a link to the state’s respective Web site. The ODS HTML statements close and reopen the HTML destination so that future output does not overwrite the HTML file that you just created.
options nodate;
proc print data=mydata label noobs;
 var st population;
 format st $compnd. ;
run;

ods html close;
ods html;

Output

Using a Format to Create Drill-down Text in an HTML Table
Using a Format to Create Drill-down Text in an HTML Table