Contents SAS/IntrNet 8.2: Application Dispatcher Previous Next

Display a Data Set with WHERE Clause and Sum Variables

This application allows you to subset the data in the resulting output. Allowing users to subset the displayed data makes an application much more useful. Two other options are available via check boxes on the form. The user can select to display a total by sales or by observation numbers or both.


The Input Component

This sample is very similar to Display a Data Set sample application. One important difference is the feature that allows the user to select one or more years of data to display.

A selection list of years is created with the following HTML code:

   <SELECT NAME="year" MULTIPLE>
   <OPTION VALUE="1981"> 1981
   <OPTION VALUE="1990"> 1990
   <OPTION VALUE="1991"> 1991
   <OPTION VALUE="1992"> 1992
   <OPTION VALUE="1993"> 1993
   <OPTION VALUE="1994"> 1994
   </SELECT>

This is slightly different from the previous selection lists because it allows the user to select more than one value from the list. The keyword MULTIPLE added to the SELECT tag enables multiple selections.

The two check boxes are created with the following HTML code:

   <INPUT TYPE="checkbox" NAME="sumvar" VALUE="sales" CHECKED>Total by Sales
   <INPUT TYPE="checkbox" NAME="observ" VALUE="yes">Display Observation numbers

The HTML code for this application is installed with the Dispatcher package in a default location of http://yourserver/sasweb/IntrNet8/dispatch/webdata2.html.


The Program Component

When you use check boxes, be careful to ensure that the proper check boxes are selected on the form. If a check box such as the observation numbers box is selected on the form, then a name/value pair such as observ=yes is passed to the Broker. However, if the check box is not selected, then the browser passes no name or value for that form element. This can be problematic for the Dispatcher program. If a macro variable that does not exist is referenced in the program, SAS software displays a warning or error message. To avoid this, use the %global statement to declare any variables that have the possibility of not being passed by the browser.

For this program use the following statement:

   %global sumvar observ year0;

The global declaration will not clear or reset any values contained in these variables, but it will make sure that these macro variables exist and are global in scope. If values were not passed, then these variables will be blank.

The next task this Dispatcher program must perform is creating a WHERE clause to subset the rows in the data set. Recall the selection list of years that allows multiple selections. If the user choose 1991, the name/value pair year=1991 is passed. The macro variable year will be used in the part of the Dispatcher program that generates a WHERE clause.

If the you choose 1981, 1991, and 1993, the Dispatcher receives all of the following name/value pairs:

At first, this looks like it might cause a problem because one name is used for three values. However, the Dispatcher handles multiple values in a special way. These three name/value pairs will actually produce the following macro variables in the SAS session:

The Dispatcher uses number suffixes to produce unique variable names. This feature allows programs to accept and process multiple name/value pairs. The details of how multiple values are created and handled by the Application Dispatcher are explained more fully in Multiple Value Pairs.

A WHERE clause can now be generated for an arbitrary number of years. Because the variable year0 contains the number of years selected, it can be used to control a DO loop. Each loop can extract the selected years from the variables year1, year2, and so on. Here is the macro that generates the WHERE clause statement:

   /* This macro code will build a WHERE clause. */
   %macro genwhr;
      %local i or;
      %global year year0;
      %if %superq(year) ne %str() %then
      %do;  /* generate a WHERE clause */
         %if %superq(year0) eq %str() %then %let year0=1;
         %let year1 = %superq(year);
         %do i = 1 %to %superq(year0);
            %let whrcls=&whrcls &or (year=%superq(year&i));
            %let or = or;
         %end;
      %end;
   %mend;

This code accounts for the following possibilities:

It is essential to realize that the year0 and other number-suffixed variables will only be created by the Dispatcher if multiple years are selected by the user. Notice the check for year not equal to blank. If this condition is false, then a year was not selected. In that case, the macro routine exits, and a WHERE clause is not generated. Thus, by not selecting a year, the full data set is displayed.

Next, notice the check for year0 having a blank value. If this is true but year is nonblank, then only a single year was selected. In that case, the macro sets year0 to a value of 1 so the DO loop will iterate only once. Finally, the program makes a call to the Data Set Formatter, passing the generated WHERE clause to produce the desired HTML table.

The complete code for this Dispatcher program is installed in the Application Server sample library in a file named webdata2.sas.


Contents SAS/IntrNet 8.2: Application Dispatcher Previous Next