Invoking SAS Programs via Browser Using get2sas Script


The Perl script provides a standardized method for creating URL-based (as opposed to HTML form-based) interfaces to SAS(r) programs which are written to conform to this poor man's "API". The "get" in "get2sas" refers to the name of the cgi-bin method used to pass parameter values to an application.

Format of the URL to Invoke

This Perl script (which can be referenced with or without the ".pl") can be invoked from an application using a URL of the form:

{cgi-bin directory}/get2sas?p={pgm-name}&p1=val1&p2=val2....&?

  • {cgi-bin directory} references the library where cgi-bin applications are stored on your server. For the oseda server this is .
  • {pgm-name} refers to a SAS program file to be invoked and passed the parameters in the remainder of the parm-list string on stdin. The file is assumed to be in the /wwwhome/uic/uicapps directory (alternate versions of the script with different assumed directories can easily be created.)
  • p1, p2, ... are parameter names to be recognized by the SAS program and val1, val2, ... are values to be associated with those parameters.
  • The trailing "?&" is required by convention - it is used by the SAS program to recognize the end of the parm list.
  • Example:
    This URL will cause the SAS system to execute the program stored in /wwwhome/uic/uicapps/ The string of parameter information following the first ? will be processed by the Perl script and then piped into the program. We do not want to get into the programming details of this specific application but you may want to concentrate on the first SAS DATA step, which reads the stdin file. This step is sufficiently constant that we have created a separate module (called that can be included in any SAS application using the interface. When this step completes, any parameter=value specification included in the parameter list will result in a SAS global variable with the parameter name being assigned that value. Thus, in this example, the parsing step uses the SAS symput function to perform the equivalent of:
      %let ftype=popests;
      %let dset=mocom96;
      %let vars=pop90 popchang pctchang; *--note +'s become blanks--;
      %let id=areaname;
    It is, of course, not a trivial matter to code the subsequent SAS steps to interpret these parameters and to do something useful with them. The key is to send useful data back to the web appliation by writing something to stdout. In this example we use the SAS "proc printto" procedure to direct the output of SAS procedures to stdout. Then, when we run the PROC PRINT step the results are piped straight back to the client browser.

    Specifying Type of Data Being Returned

    In our example we generated a plain text file - the proc print report. In these cases it is not necessary to tell the client browser what is coming since plain text is the default. If, however, you application is creating a dynamic HTML document you need to generate the line
    Content-type: text/html
    followed by a null line. You can achieve this with a simple SAS data step placed at the top of your program:

    file stdout; put 'Content-type: text/html' / / /; run;

    Generating a .gif Image Directly

    You can use the various gif device drivers in SAS to create graphics output. In most cases you'll want to write these to files and then create an HTML output document that references these files with IMG tags. But there are times when you may want to have a link defined so that when the user clicks on it a graphic image is immediately delivered to their screen. A very simple example of this is stored in /uic/uicapps/
    You execute this module - with no parameters other than the name of the program - using .

    Last revised 7-30-97, jgb