Invoking SAS Programs via Browser Using get2sas Script
Overview
The get2sas.pl 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 get2sas.pl
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....&?
where:
Example:
http://www.oseda.missouri.edu/cgi-bin/get2sas?p=procp&ftype=popests&dset=mocom96&vars=pop90+popchang+pctchang&id=areaname&?
This URL will cause the SAS system to execute the program stored in
/wwwhome/uic/uicapps/procp.sas. The string of parameter information
following the first ? will be processed by the Perl script and then piped
into the procp.sas
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
parsprms.sas) that can be included in any SAS application using the get2sas.pl
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/sampgif1.sas.
You execute this module - with no parameters other than the name of the program - using
http://www.oseda.missouri.edu/cgi-bin/get2sas?p=sampgif1&?& .
Last revised 7-30-97, jgb