Roald Euller's Home Page

Example of a batch SAS program running under cgi-bin


Example of a SAS program called from a perl script and running under cgi-bin. The SAS program is invoked to direct output to stdout (using the command line option "-stdio"). A sysparm parameter supplies choices generated by an html form. The macro "setup" parses the sysparm. The macro "tabulate " uses the sysparm arguments to generate a custom table. Proc tabulate output is directed to stdout, where it is read by the calling perl script and formatted as an html page for the user. Note that the SAS program knows nothiung about the fact that its output is destined for an html page: because it is invoked from the command line with the -stdio parameter the program simply streams the normal output of proc tabulate to stdout.



options nodate nonumber nocenter;
options pagesize=1000;  /* allow for a REALLY big table */
options linesize=256;

libname ddin "/spider/a/https/cgi-bin/euller";

/* macro to parse sysparm.  arg 1 is an argument count,
   args 2-cnt are the class and var variable names.  More
   sophisticated programs will pass in more items. */

%macro setup;

   %global argcnt;

   %let argcnt = %scan("&sysparm", 1, " ");

   %do i = 1 %to &argcnt;
      %global a&i;
      %let a&i = %scan("&sysparm", %eval(&i+1), " ");
   %end;

%mend setup;

%macro tabulate(class, var);

   proc tabulate data=ddin.arf (keep=year &class &var);
      title1 "Statistics from the 1990 Area Resource File (ARF)";
      var &var;
      class &class year;

      table
	 (&class all),
	 (year) *
	    &var*sum=" "*f=comma20.
      / rts = 22
      ;

   run;

%mend tabulate;

%setup;
%tabulate( &a1, &a2 );