Contents SAS/IntrNet 1.2: Application Dispatcher Previous Next
 

Tabulate Procedure

This application illustrates the computational power of the Application Dispatcher. The HTML form provides options that perform different tabulations of the same set of data. This capability is possible because the Dispatcher is more than just a data server.


The HTML Page

The HTML page for the Tabulate Procedure application is quite simple. It contains a set of four check boxes, a selection list, and a submit button. This sample application uses the HTML Tabulate Formatter, one of the HTML Formatting Tools provided by SAS, to create an HTML-formatted table. This tool will produce all of the HTML output for this application! The user interface is not fancy, but the capabilities that it highlights are very noteworthy. By selecting the various check boxes, the user controls which variables will be tabulated in the resulting table.

The check boxes on this form allow users to select the statistics to display. Check boxes are created by using the INPUT tag with a type of CHECKBOX. Here is the code for the four check boxes on this page:

Number of Sales
Average Sale
Smallest Sale
Largest Sale

A selection list field is provided from which the user can select a row variable. The selection list begins with the <SELECT> tag and ends with the </SELECT> tag. A name attribute is assigned to the field within the select tag. Items are added to the selection list with <OPTION> tags. This selection list code lets the user choose a row variable to tabulate.

<SELECT NAME="row">
<OPTION VALUE="year*month">Year and Month
<OPTION VALUE="year">Year
<OPTION VALUE="month">Month
</SELECT>

These two components along with some descriptive text and a submit button complete the form. The HTML code for this application can be found in the Broker package sample directory in a file named tabulate.html. The code produces a form that looks like this:

Tabulate

For more detailed information on creating the input component of a Dispatcher application, see Input Component Details.

The Dispatcher Program

The Dispatcher program for this application is very simple, thanks to the Tabulate Formatter. The Tabulate Formatter works by a capture on/capture off mechanism. A macro call is made to %tab2htm before SAS code is submitted. The parameter capture=on engages the Formatter. Then SAS code is submitted, and the Tabulate Formatter traps whatever would usually be sent to the output window. At the end of the program, another call to %tab2htm is made with the parameter capture=off, which disengages the Tabulate Formatter.

In addition to turning capture mode off, the Tabulate Formatter must be instructed where to send the generated HTML. Because all HTML output produced by Dispatcher programs should be sent to fileref _WEBOUT, the parameter htmlfref=_WEBOUT is used.

Lastly, recall from the hello program that each Dispatcher program must return an HTTP header followed by a null record. Here is an example:

  put 'Content-type: text/html';
  put ;

The parameter runmode=s instructs the Tabulate Formatter to print the HTTP header before creating any output. We could have dropped the runmode parameter and preceded the call to the Formatter with a simple DATA step containing these PUT statements, which would be equivalent to the first example. If the first output produced from a Dispatcher program is created by a Formatting Tool, then it is convenient to simply supply runmode=s, allowing the Formatting tool to generate the HTTP header. However, it is important not to forget that the HTTP header must always be written either by your code or by the Formatting Tools.

Using the Tabulate Formatter in a Dispatcher program takes this general form:

  %tab2htm(capture=on);

    proc tabulate data=data set FORMCHAR='82838485868788898a8b8c'x;

    more proc tabulate steps . . .

  %tab2htm(capture=off,
           htmlfref=_webout,
           runmode=s,
           openmode=replace);

The complete code for this Dispatcher program is contained in the Application Server package in a file named tabulate.sas.

Based on the selection that the user makes on the HTML form in this application, one of three values is passed to this program in the variable row. The macro statement %superq(row) will resolve to year*month, year, or month. Since resolution of SAS macro statements occurs before any procedures are executed, the tabulate procedure code is resolved into the proper syntax and the desired tabulation is performed. In the case of a row value of year*month, one section of the procedure will require year*month and another will require year month. To do this, a new variable is created and the asterisk is translated to a space.

One of SAS software's greatest strengths is that it provides you with an extensive, powerful array of analytical procedures such as the tabulate procedure. Procedures to perform cross tabulations, charts, statistical analysis, summaries, and graphics can be leveraged in your Dispatcher applications. This is much much more than a data base tool! Read the other example application sections to learn more or jump right to the details about the program component in Dispatcher Program Details.


Contents SAS/IntrNet 1.2: Application Dispatcher Previous Next