Setting the HTML title tag in SAS ODS (the right way)

In our department and various places on the Intertubes, SAS programmers set the HTML title tag (which sets the title in web browsers and on search engines) in ODS using the headtext option:

ods html
 headtext="<title>My great report</title>" /* wrong! */

This may work in some situations, but it’s ugly and wrong. To see why, view the raw HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<title>My great report</title>
<meta name="Generator" content="SAS Software, see" sasversion="9.1">
<meta http-equiv="Content-type" content="text/html; charset=windows-1252">
<title>SAS Output</title>

Each HTML page should only have one TITLE tag, but this method creates an additional tag instead of replacing the first. Some web browsers and spiders may use the second tag instead of the first, and the document won’t validate as HTML (not that you can fix SAS’s HTML completely). If your document is only on an intranet think of personal and corporate document indexing systems (Google Search Appliance, Google Desktop Search, Windows Search, etc.), and even if it works now, you want to future-proof your HTML reports when (not if) new technology comes in to the mix.

I discovered the correct way thanks to Chevell Parker:

ods html
 file="foo.html" (title="My great report"); /* correct way to set the HTML title tag */

This was tested on SAS 9.1.3 SP4 on Windows XP SP3.

(UPDATE August 18, 2010) Setting the ODS title in a stored process (created with Enterprise Guide or with SAS Management Console) is more complicated because the automatic macro %STPBEGIN opens ODS, and you should not call open ODS HTML yourself. If you can’t call ODS HTML, then how do you pass options to it? It appears not to be possible to do all within Enterprise Guide, and the best way I have found is to use Enterprise Guide to create the stored process without the title. Then, after the stored process is created, edit the generated .SAS file (using any text editor including EG, base SAS, Notepad, VIM, Emacs, etc) and add the following line:


/* The global statement varies depending on your prompts */
%global PROMPT_DATE;

/* !!! This is the line you add, and add it here after ProcessBody and before STPBEGIN. */
%let _ODSOPTIONS=(title='My great report');		

/* The following automatic macro (which you should not change) opens ODS HTML for you */

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s