Contents SAS/IntrNet 8.2: Application Dispatcher Previous Next

Creating Dispatcher Applications Using Pie Charts

This sample illustrates how to produce graphics output by using the Application Dispatcher. It requires that you have SAS/GRAPH software licensed and installed.


The Input Component

The HTML page for this sample application provides the most essential information. To keep the program code simple, the only variables that have been used are the _SERVICE, _PROGRAM, and _DEBUG Dispatcher variables. Because none of these values dynamically change the program code, every invocation of this application produces the same graphic. The purpose of this sample is to provide a simple "how to" explanation for creating graphics.

The HTML code for this application is installed with the Dispatcher package in a default location at http://yourserver/sasweb/IntrNet8/dispatch/webgraph.html. The code produces a form that similar to this:

Graphics Output Sample Application

The Program Component

The following describes the steps performed by a Dispatcher program

  1. The first output that must be produced is a valid content-type header. This is true of all Dispatcher programs. Because this program uses a GIF graphics driver, the content type is image/gif.
  2. A DATA step is used to write out the header.
  3. Graphics options are set.
  4. The graphics procedure is invoked with a GIF driver.
  5. The output is directed to the special _WEBOUT fileref.

Here is the complete code for this Dispatcher program.

   data _null_;
      file _webout;
      put 'Content-type: image/gif';
      put;
   run;


   goptions gsfname=_webout gsfmode=replace dev=gif733
      ftext=swiss;

   pattern1 value=solid color=yellow;
   pattern2 value=solid color=cyan;
   pattern3 value=solid color=green;
   pattern4 value=solid color=black;
   pattern5 value=solid color=red;
   pattern6 value=solid color=blue;

   proc gchart data=sashelp.retail;
      pie year/sumvar=sales;
      pattern v=s;
   run;
   quit;

The resulting graphic is a pie chart of the sashelp.retail data set. The gsfname option directs the SAS/GRAPH procedure to write the image output to the special fileref and back to the Web browser. Notice the gsfmode=replace option. This is very important. It is tempting to use an append mode here because you have already written to a header in the previous DATA step. Don't use the append mode. A gsfmode of replace must always be used, otherwise the procedure may skip writing out some critical GIF initialization information.

It is impossible to overwrite data already sent to _WEBOUT. Because the Application Dispatcher uses TCP/IP sockets to flow the data from your program to the Web browser, the _WEBOUT fileref is always appending. As with standard output and pipes, _WEBOUT cannot replace what has been previously written.


Contents SAS/IntrNet 8.2: Application Dispatcher Previous Next