Adding Links and Enhancements with the URL=, HTML=, and HTML_LEGEND= Options

About the URL=, HTML=, and HTML_LEGEND= Options

The URL=, HTML= and HTML_LEGEND= options can be used in a number of statements that generate graphs. These options are use to add drill-down links, data tips, and enhancements to Web presentations that are generated with the following device drivers:
  • GIF, JPEG, PNG, or SVG
  • JAVA and ACTIVEX
  • JAVAMETA
The following table shows what each of these options can add to a graph.
Option
What It Can Add to a Graph
URL=
drill-down links to the data elements
HTML=
drill-down links, data tips, and enhancements to the data elements
HTML_LEGEND=
drill-down links, data tips, and enhancements to the graph legend values
As shown in the table, both the URL= option and the HTML= option can be used to add drill-down links to the data elements of a graph. You must use either the URL= option or the HTML= option, but not both. If you just want to link your graph data elements to a URL, use the URL= option or the HTML= option. However, if you want to add data tips or other enhancements to your graph data elements, you must use the HTML= option.
Note: If you specify both the URL= and the HTML= option in your SAS/GRAPH procedure statement, the URL= option is ignored. A warning message appears in the SAS log in that case.

Link Variables and Enhancement Variables

The URL=, HTML=, and HTML_LEGEND= options identify a variable in the data set that contains the link information. The variable can contain a link URL only or it can contain other functionality, such as a data tip or a link target. If the variable contains only a link URL, it is referred to as a link variable. If the variable contains a data tip, link target, or other functionality, because it does more than establish a link, it is referred to as an enhancement variable. Only link variables can be used with the URL= option. Both link variables and enhancement variables can be used with the HTML= and HTML_LEGEND= options.
The syntax of the link variable value depends on the link option with which it is used. For the URL= option, the link value syntax is as follows:
"URL<#anchor name>"
For the HTML= and HTML_LEGEND= options, the link value syntax is as follows:
"href='URL<#anchor name>'"
An enhancement variable is used when other attributes such as TITLE= or TARGET= are included in the link value in order to provide additional functionality. The enhancement value syntax is as follows:
"attribute='value' <...attribute='value'>"
where attribute can be an HTML <A> tag attribute such as HREF= or TITLE=, or an SVG device driver attribute such as ONMOUSEOVER (see Enhancing Drill-Down Behavior in SVG Presentations Using HTML Attributes).
The URL= option provides the simplest means of adding drill-down links to your presentation. You specify only the URL string, and the SAS/GRAPH software codes the URL into an HREF= attribute-value pair for you. The HTML= and HTML_LEGEND= options enable you to add one or more HTML <A> tag or SVG device driver attribute-value pairs to your link value in order to add functionality to your links. However, you must code the attribute-value pairs yourself, which can be complicated when multiple attribute-value pairs are included.
Note: Values created for the URL= option, and values created for the HTML= and HTML_LEGEND= options are not interchangeable.

Working with Link and Enhancement Variables

Creating Link and Enhancement Variables in a Web Presentation

To create link and enhancement variables for your Web presentation, you must do the following:
  • define the link variable or enhancement variable, or both
  • add data to the link variable or enhancement variable, or both
  • for a link variable, in your SAS/GRAPH procedure statement, do one of the following:
    • identify the variable in the URL= option
    • identify the variable in the HTML= option, the HTML_LEGEND= option, or both
  • for an enhancement variable, in your SAS/GRAPH procedure statement, identify the variable in the HTML= option, the HTML_LEGEND= option, or both
For example, assume that you have a Web-based sales presentation that consists of a total sales bar chart in file sales.htm and a detailed sales chart for each region in file report.htm. Each bar in the total sales chart indicates the total sales for one of three corporate regions: central, southern, and western. You want to link each bar in your total sales chart to the detailed sales report for that region in file report.htm as shown in the following figure.
Chart in File sales.htm Linked to a Chart in File reports.htm
In addition, when a bar in the total sales chart is clicked, you want the drill-down chart in file reports.htm to be opened in a separate browser window named REGIONSALES.
To create the drill-down links for your presentation, perform the following steps:
  1. Determine the link value that you need to implement your link behavior. Since you want your drill-down graphs to open in a separate browser window, your link value must include the URL to the regional sales report in file report.htm and the TARGET= attribute as shown in the following example:
    href="reports.html#west" target="regionsales"
  2. Determine the type of variable that you need to create and the syntax for the link value. Because the value in this case includes a URL and the TARGET= attribute, you must use an enhancement variable. Therefore, the syntax for the link value is as follows:
    "href='reports.html#west' target='regionsales'"
  3. Define your link variable in your data set. The following code fragment defines a link variable named RPT and assigns that variable a length of 80 characters.
    data regsales;
       input Region State Sales;
       length RPT $80;
    Note: When you create your link variable, be sure to define it with a length that is sufficient to contain your link value. There is no limit on the length of the variable.
  4. In your DATA step, assign a value to your link variable as shown in the following example:
    RPT="href='reports.html#west' target='regionsales'"
    For information about assigning values to your link variable, see Assigning Values to Link and Enhancement Variables.
  5. In your SAS/GRAPH procedure statement, use the HTML= option to identify the enhancement variable RPT as shown in the following code fragment.
    title "Regional Sales";
    proc gchart data=regsales;
       vbar region / sumvar=sales subgroup=region
         html=RPT;
    run;

Considerations When Using Anchored Links and Link Targets

When you link to an anchor in the same HTML file, you can omit the HTML filename and include only the anchor name in the URL as shown in the following example:
RPT="href='#west' target="regionsales"
However, if you want to use an SVG device to generate your Web presentation, to link from the SVG document to an anchor in the parent HTML file, you must include the HTML filename and the anchor name in the link URL. If you omit the HTML filename in that case, the link will not work.
When you use the TARGET= attribute to open a drill-down link in a separate browser window, be aware of the following:
  • If a pop-up blocker is active in your Web browser, it might prevent the new window from opening. In that case, you must disable or temporarily override the pop-up blocker, or you must modify the pop-up blocker settings to allow the window to open. Refer to your pop-up blocker documentation for more information.
  • An SVG document might not be permitted to open a new window in the Microsoft Internet Explorer 7 and Internet Explorer 8 browsers.

Assigning Values to Link and Enhancement Variables

The most obvious method of adding these variables to your data set is to manually add them to the desired observations in your data set. This method is not practical or feasible in many cases. In those cases, you can use IF/THEN statements or variable substitution in your DATA step.
The following diagram shows how link variables are assigned to a bar chart. The three bars represent regional sales for a company's central, southern, and western regions.
Links in Drill-Down Graphs
A Link from File sales.htm to Anchor WEST in File reports.htm
Each bar in the chart links to an anchor tag in an HTML file named reports.htm. The anchor names in the linked file are “Central,” “South,” and “West.” In the following DATA step, IF/THEN/ELSE statements are used to assign values to the link variable, which is then identified using the HTML= option.
/* create data set REGSALES */
data regsales;
 length Region State $ 8;
 format Sales dollar8.;
 input Region State Sales;
 length rpt $80; /* the link dest. variable */
datalines;
West CA 13636
West OR 18988
West WA 14523
Central IL 18038
Central IN 13611
Central OH 11084
Central MI 19660
South FL 14541
South GA 19022
;
/* assign HREF values to link dest. variable */
data regsales;
 set regsales;
 if Region="Central" then
  rpt="HREF='reports.htm#central' target='regionsales'";
 else if Region="South" then
  rpt="HREF='reports.htm#south' target='regionsales'";
 else if Region="West" then
  rpt="HREF='reports.htm#west' target='regionsales'";
run;

goptions reset=all device=ActiveX;

ods html close;
ods html file="sales.htm";

/* create chart that uses link targets */
title "Regional Sales";
proc gchart data=regsales;
   vbar region / sumvar=sales
     html=rpt;
run;

/* create the link targets */
ods html file="reports.htm" anchor="south";
title "Southern Sales";
proc gchart data=regsales;
 where region="South";
 vbar state /sumvar=sales;
run;

ods html anchor="central";
title "Central Sales";
proc gchart data=regsales;
 where region="Central";
 vbar state /sumvar=sales;
run;

ods html anchor="west";
title "Western Sales";
proc gchart data=regsales;
 where region="West";
 vbar state /sumvar=sales;
run;
quit;
ods html close;
ods html;
REGSALES Data Set
Values in the REGSALES Data Set
You could use variable substitution to simplify the DATA step. The URLs used in the preceding program all use the same HTML filename, but the anchor differs depending on the value of the Region variable. You can concatenate the value of the Region variable to the common HTML filename to generate the drill-down URLs.
data regsales;
 set regsales;
 rpt="HREF='reports.htm#"||Region||"' target='regionsales'";
run;

Links in GIF, JPEG, PNG, and SVG Presentations

To add drill-down functionality to images generated with the GIF, JPEG, PNG, SVG, SVGT, SVGZ, and SVGVIEW drivers, do one of the following:
  • Use the URL= option with a SAS/GRAPH procedure to add drill-down functionality to the graph data elements.
  • Use the HTML= option with a SAS/GRAPH procedure to add drill-down functionality to the graph data elements.
  • Use the HTML_LEGEND= option with a SAS/GRAPH procedure to add drill-down functionality to the legend entries.
  • Use both the HTML= option and the HTML_LEGEND= option with a SAS/GRAPH procedure to add drill-down functionality to the legend entries.
Additional functionality is available through the use of HTML attributes with the SVG graphics devices. For more information, see Enhancing Drill-Down Behavior in SVG Presentations Using HTML Attributes.

Links in ACTXIMG and JAVAIMG Presentations

To add drill-down functionality to an image created with the ACTXIMG or JAVAIMG device drivers, use the HTML= option as described in Adding Links and Enhancements with the URL=, HTML=, and HTML_LEGEND= Options.

Links in ACTIVEX Presentations

To add drill-down functionality to the ActiveX control created with the ACTIVEX device driver, use the URL= option or the HTML= option as described in Adding Links and Enhancements with the URL=, HTML=, and HTML_LEGEND= Options.

Links in JAVA Presentations

To generate drill-down presentations using Java, specify the DEVICE=JAVA graphics option to generate your graphs using the Graph applet. The Graph applet is a Java applet that provides drill-down functionality by default. For an example, see Creating a Drill-Down Java Presentation for the Web.

Links in Metaview Applet Presentations

To generate drill-down presentations for the Metaview applet use either the HTML= or the HTML_LEGEND= options or both and an enhancement variable, as introduced in Adding Links and Enhancements with the URL=, HTML=, and HTML_LEGEND= Options.

Links in Animated GIF Presentations

SAS/GRAPH does not directly support drill-down functionality for animated GIFs. To enable drill-down functionality from an animated GIF, use any third-party tools that are available to you. You can make the entire image a hotspot by including the <IMG> tag inside an <A HREF=> tag.