Return to ODS MARKUP

Base SAS

The htmlscroll Tagset Creates Scrolling Tables

HTML output that scrolls tables has always been a strong desire for many SAS users. With the Document Object Model (DOM) Web standards finally taking hold, it is now possible to write JavaScript code that provides scrolling controls for all tables that exceed a given number of rows.

Integrating the working JavaScript into a tagset was relatively simple. The hardest part was ensuring that the quoting was done correctly. The htmlscroll tagset is supported in SAS 9.1 and later.

A Simple Example

This tagset inherits most of its behavior from the HTML4 tagset. The HTML4 tagset is what you are using when you invoke the ODS HTML destination. By default, any table with more than eight rows gets scrolling controls. The only thing this tagset adds is scrolling control for tables with more than eight rows.

   ods tagsets.htmlscroll file="scroll.html";

   proc print data=sashelp.class; run;

   ods _all_ close;

Changing the Table Size

The maximum row size of eight is the default, but you can change that by setting a macro variable before the opening ODS statement. The scroll size can also be changed by adding it to the URL when the page is loaded. Another parameter controls the minimum size of a table that should be scrolled. The default value is (2 * batch_size) + 1.

   /* Change the default table size from 8 data rows to 12 */

   %let scroll_batch_size = 12;

   /* Change the default minimum scrollable table size from (2 * batch size)+1  to 30 */

   %let scroll_long_table_length = 30;

The options can also be changed with the OPTIONS feature of ODS MARKUP. Options are name-value pairs that are passed directly to the tagset. They can be anything; it is up to the tagset to use them. The OPTIONS feature is only available in SAS 9.1.3 and later.

The htmlscroll tagset uses the same names for the options as it does for the macro variables. Here is an example of changing the default scrolling batch size:

   ods tagsets.htmlscroll file="scroll.html"

   proc print data=sashelp.class;

   ods tagsets.htmlscroll close;

Invoking the URL with a size also changes the table size and changes the size of a table that qualifies as scrollable.

Two parameters control the detection of an excessively long table, and the number of rows to be displayed in a converted table: long_table_length and batch_size. Here are two examples that show how to use the URL parameters:";';

Changing the Scroll Controls

By default, the scroll controls are textual. But images can be substituted. The download file contains the PNG files needed for all the controls. The following list shows the image names and how they are used. The images must be available for loading by the Web page.

To turn on the use of images, set another macro variable. It can also be passed as an option on the ODS statement.

   %let scroll_control_images = yes;

   /* OR */

   ods tagsets.htmlscroll options(scroll_control_images='yes');

Changing the Default Settings

There is a single event that defines the default settings for the htmlscroll tagset. To change the defaults, only this one needs to be overridden or changed. The following example creates a new tagset that has different defaults than the original.

   proc template;
      define tagset tagsets.htmlscroll2;
      parent = tagsets.htmlscroll;

      define event set_scroll_options_default;
         set $default_scroll_batch_size '10';
         set $default_scroll_long_table_length '(2*batch_size)+1';
         /* unset $default_scroll_control_images; */
         set $default_scroll_control_images 'True';


A special event has been created to facilitate changing the image names. By isolating the name definitions into a special event, the htmlscroll tagset can be easily modified through inheritance. The following tagset creates a new scrolling tagset that uses different images for its controls.

   proc template;
      define tagset tagsets.htmlscroll3;
      parent = tagsets.htmlscroll2;

      define event image_names;
         set $top_image = '';
         set $page_up_image = '';
         set $up_image = '';
         set $down_image = '';
         set $page_down_image = '';
         set $bottom_image = '';



With the tools in this topic, you should be able to create HTML with scrolling tables from SAS. The tagset and examples are available in a zipped archive, This tagset does not have many events, so it could easily be used as a parent tagset to other HTML tagsets that add other features to the HTML.

Your Turn

Send e-mail to with your comments.

Last Updated: v1.59, 8 November 2007