Creating HTML Output with ODS

The ODS HTML Statement

To create simple HTML output files in the default location using the default file-naming conventions, you do not have to specify the ODS HTML statement. However, to create HTML output with options specified, you open the HTML destination using the ODS HTML statement.
Note: You do not have to specify the ODS HTML statement to produce basic HTML output unless the HTML destination is closed.
Syntax, ODS HTML statement:
ODS HTML BODY = file-specification;
ODS HTML CLOSE ;
  • file-specification identifies the file that contains the HTML output. The specification can be any of the following:
    • a quoted string that contains the HTML filename (use only the filename to write the file to your current working directory, such as C:UsersStudent1Documents and SettingsusernameMy DocumentsMy SAS Files). Example: ODS HTML BODY=myreport.html”;
    • a quoted string that contains the complete directory path and HTML filename (include the complete pathname if you want to save the HTML file to a specific location other than your working directory). Example: ODS HTML BODY=c:UsersStudent1 eportdirmyreport.html”;
    • a fileref (unquoted file shortcut) that has been assigned to an HTML file using the FILENAME statement. Example: FILENAME MYHTMLc: eportdirmyreport.html”; ODS HTML BODY=MYHTML;
    • a SAS catalog entry in the form entry-name.html. Note that the catalog name is specified in the PATH= option and the entry-name.html value for the BODY= option is unquoted. Example: ODS HTML PATH=work.mycat BODY=myentry BODY=bodyfile.html;
Tip
FILE= can also be used to specify the file that contains the HTML output. FILE= is an alias for BODY=.
Tip
You can also use the PATH= option to explicitly specify a directory path for your file.

Example: Creating Output with PROC PRINT

The following program creates PROC PRINT output in an HTML file. The ODS HTML BODY= option specifies the file C:UsersStudent1certadmit.html in the Windows operating environment as the file that contains the PROC PRINT results.
ods html body='C:UsersStudent1certadmit.html';
proc print data=cert.admit label;
  var sex age height weight actlevel;
  label actlevel='Activity Level';
run;
ods html close;
ods html path="%qsysfunc(pathname(work))";
The HTML file admit.html contains the results of all procedure steps between the ODS HTML statement and ODS HTML CLOSE statement.
Output 16.1 HTML Output
HTML Output

Creating HTML Output with a Table of Contents

Overview

The BODY= specification is one way to create an HTML file containing procedure output. To create an HTML file that has a table of contents with links to the output of each specific procedure, specify additional files in the ODS HTML statement.
Syntax, ODS HTML statement to create a linked table of contents:
ODS HTML
BODY=body-file-specification
CONTENTS=contents-file-specification
FRAME=frame-file-specification;
ODS HTML CLOSE;
  • body-file-specification is the name of an HTML file that contains the procedure output.
  • contents-file-specification is the name of an HTML file that contains a table of contents with links to the procedure output.
  • frame-file-specification is the name of an HTML file that integrates the table of contents and the body file. If you specify FRAME=, you must also specify CONTENTS=.
Tip
To direct the HTML output to a specific storage location, specify the complete pathname of the HTML file in the file-specification.
Here is an example that does the following:
  • The BODY= specification creates the file data.html in C:UsersStudent1cert directory. The body file contains the results of the two procedures.
  • The CONTENTS= specification creates the file toc.html in the C:UsersStudent1cert directory. The table of contents file has links to each procedure output in the body file.
  • The FRAME= specification creates the file frame.html in the C:UsersStudent1cert directory. The frame file integrates the table of contents and the body file.
HTML Output with Table of Contents
ods html body='C:UsersStudent1certdata.html'
  contents='C:UsersStudent1cert	oc.html'
  frame='C:UsersStudent1certframe.html';
proc print data=cert.admit (obs=10) label;
  var id sex age height weight actlevel;
  label actlevel='Activity Level';
run;
proc print data=cert.stress2 (obs=10); 
  var id resthr maxhr rechr;
run;
ods html close;
ods html path="%qsysfunc(pathname(work))";

Viewing Frame Files

The Results window does not display links to frame files. In the Windows environment, only the body file automatically appears in the internal browser or your preferred web browser.
To view the frame file that integrates the body file and the table of contents, select File> Open from within the internal browser or your preferred web browser. Then open the frame file that you specified using FRAME=. In the example above, this file is frame.html, which is stored in the Cert directory in the Windows environment.
The frame file, frame.html, is shown below.
Figure 16.2 Frame File, frame.html (partial output)
Partial Output: Frame File, frame.html

Using the Table of Contents

The table of contents that was created by the CONTENTS= option contains a numbered heading for each procedure that creates output. Below each heading is a link to the output for that procedure.
Tip
On some browsers, you can select a heading to contract or expand the table of contents.
Figure 16.3 Table of Contents
Table of Contents

Using Options to Specify Links and Paths

Overview

When ODS generates HTML files for the body, contents, and frame, it also generates links between the files using HTML filenames that you specify in the ODS HTML statement. If you specify complete pathnames, ODS uses those pathnames in the links that it generates.
The following ODS statement creates a frame file that links to C:UsersStudent1cert oc.html and C:UsersStudent1certdata.html, and a contents file that has links to C:UsersStudent1certdata.html.
ods html body='C:UsersStudent1certdata.html'
		 contents='C:UsersStudent1cert	oc.html'
		 frame='C:UsersStudent1certframe.html';
A portion of the source code for the HTML file frame.html is shown below. Notice that the links have the complete pathnames from the file specifications for the contents and body files.
Example Code 16.1 Source Code for the HTML File Frame.html
<FRAME MARGINWIDTH="4" MARGINHEIGHT="0" SRC="C:UsersStudent1cert	oc.html"
	NAME="contents" SCROLLING=auto>
<FRAME MARGINWIDTH="9" MARGINHEIGHT="0" SRC="C:UsersStudent1certdata.html"
	NAME="body" SCROLLING=auto>
These links work when you are viewing the HTML files locally. If you want to place these files on a web server so that others can access them, then the link needs to include either the complete URL for an absolute link or the HTML filename for a relative link.

The URL= Suboption

To provide a URL that ODS uses in all the links that it creates to the file, specify the URL= suboption in the BODY= or CONTENTS= file specification. You can use the URL= suboption in any ODS file specification except FRAME= (because no ODS file references the frame file).
Syntax, URL= suboption in a file specification:
(URL= “Uniform-Resource-Locator”;
  • Uniform-Resource-Locator is the name of an HTML file or the full URL of an HTML file. ODS uses this URL instead of the file specification in all the links and references that it creates that point to the file.
Tip
The URL= suboption is useful for building HTML files that might be moved from one location to another. If the links from the contents and page files are constructed with a simple URL (one name), they work as long as the contents, page, and body files are all in the same location.

Example: Relative URLs

In this ODS HTML statement, the URL= suboption specifies only the HTML filename. This is the most common style of linking between files because maintenance is easier. The files can be moved as long as they all remain in the same directory or storage location.
ods html body='C:UsersStudent1certdata.html' (url='data.html')
  contents='C:UsersStudent1cert	oc.html' (url='toc.html')
  frame='C:UsersStudent1certframe.html';
The source code for frame.html has only the HTML filename as specified in the URL= suboptions for the body and contents files.
Example Code 16.2 Source Code for the HTML File Frame.html
<FRAME MARGINWIDTH="4" MARGINHEIGHT="0" SRC="toc.html"
	NAME="contents" SCROLLING=auto>
<FRAME MARGINWIDTH="9" MARGINHEIGHT="0" SRC="data.html"
	NAME="body" SCROLLING=auto>

Example: Absolute URLs

Alternatively, in this ODS HTML statement, the URL= suboptions specify complete URLs using HTTP. These files can be stored in the same or different locations.
ods html body='C:UsersStudent1certdata.html'
		(url='http://mysite.com/cert/data.html')
		contents='C:UsersStudent1cert	oc.html'
		(url='http://mysite.com/cert/toc.html')
		frame='C:UsersStudent1certframe.html';
As you would expect, the source code for Frame.html has the entire HTTP addresses that you specified in the URL= suboptions for the body and contents file.
Example Code 16.3 Source Code for the HTML File Frame.html
<FRAME MARGINWIDTH="4" MARGINHEIGHT="0" SRC="http://mysite.com/cert/data.html"
	NAME="contents" SCROLLING=auto>
<FRAME MARGINWIDTH="9" MARGINHEIGHT="0" SRC="http://mysite.com/cert/toc.html"
	NAME="body" SCROLLING=auto>
Tip
When you use the URL= suboption to specify a complete URL, you might need to move your files to that location before you can view them.

The PATH= Option

Use the PATH= option to specify the location of the files.
Syntax, PATH= option with the URL= suboption:
PATH=file-location-specification<(URL=NONE | “Uniform-Resource-Locator>
  • file-location-specification identifies the location where you want HTML files to be saved. It can be one of the following:
    • the complete pathname to an aggregate storage location, such as a directory or partitioned data set
    • a fileref (file shortcut) that has been assigned to a storage location
    • a SAS catalog (libname.catalog)
  • Uniform-Resource-Locator provides a URL for links in the HTML files that ODS generates. If you specify the keyword NONE, no information from the PATH= option appears in the links or references.
    If you do not use the URL= suboption, information from the PATH= option is added to links and references in the files that are created.
Note: In the z/OS operating environment, if you store your HTML files as members in a partitioned data set, the PATH=value must be a PDSE, not a PDS. You can allocate a PDSE within SAS as shown in this example:
filename pdsehtml '.example.htm'
	dsntype=library dsorg=po
	disp=(new, catlg, delete);
You should specify valid member names for the HTML files (without extensions).

Example: PATH= Option with URL=NONE

In the following program, the PATH= option directs the files data.html, toc.html, and frame.html to the C:UsersStudent1cert directory in the Windows operating environment. The links from the frame file to the body and contents files contain only the HTML filenames data.html and toc.html.
ods html path='C:UsersStudent1cert' (url=none)
  body='data.html'
  contents='toc.html'
  frame='frame.html';
proc print data=cert.admit;
run;
proc print data=cert.stress2;
run;
ods html close;
ods html path="%qsysfunc(pathname(work))";
This program generates the same files and links as the previous example in which you learned how to use the URL= suboption with the BODY= and CONTENTS= file specifications. However, it is simpler to specify the path once in the PATH= option and to specify URL=NONE.
Tip
If you plan to move your HTML files, you should specify URL=NONE with the PATH= option to prevent information from the PATH= option from creating URLs that are invalid or incorrect.

Example: PATH= Option without the URL= Suboption

In the following program, the PATH= option directs the files data.html, toc.html, and frame.html to the C:UsersStudent1cert directory in the Windows operating environment. The links from the frame file to the body and contents files contain the complete pathnames, C:UsersStudent1certdata.html and C:UsersStudent1cert oc.html:
ods html path='C:UsersStudent1cert'
  body='data.html'
  contents='toc.html'
  frame='frame.html';
proc print data=cert.admit;
run;
proc print data=cert.stress2;
run;
ods html close;
ods html path="%qsysfunc(pathname(work))";

Example: PATH= Option with a Specified URL

In the following program, the PATH= option directs the files data.html, toc.html, and frame.html to the C:UsersStudent1cert directory in the Windows operating environment. The links from the frame file to the body and contents files contain the specified URLs, http://mysite.com/cert/data.html, and http://mysite.com/cert/toc.html:
ods html path='C:UsersStudent1cert (url='http://mysite.com/cert/')
  body='data.html'
  contents='toc.html'
  frame='frame.html';
proc print data=cert.admit;
run;
proc print data=cert.stress2;
run;
ods html close;
ods html path="%qsysfunc(pathname(work))";

Changing the Appearance of HTML Output

Style Templates

You can change the appearance of your HTML output by specifying a style in the STYLE= option in the ODS HTML statement. Here are some of the style templates that are currently available:
  • Banker
  • BarrettsBlue
  • Default
  • HTMLblue
  • Minimal
  • Statistical
Tip
To see a list of styles that SAS supplies, submit the following code:
proc template;
  list styles/store=sashelp.tmplmst;
run;
Syntax, STYLE= option:
STYLE=style-name;
  • style-name is the name of a valid SAS or user-defined style template.
Tip
Do not enclose style-name in quotation marks.

Example: The STYLE= Option (Banker Style)

In the following program, the STYLE= option applies the Banker style to the output for the PROC PRINT step:
ods html body='C:UsersStudent1certdata.html'
  style=banker;
proc print data=cert.admit label;
  var sex age height weight actlevel;
run;
ods html close;
ods html path="%qsysfunc(pathname(work))";
Figure 16.4 PROC PRINT Output with Banker Style Applied (partial output)
PROC PRINT Output with Banker Style Applied (partial output)
Note: Your site might have its own, customized, style templates.
Last updated: August 23, 2018
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.144.108