Home

Features

Software

Quick Install

SAS Side

The "Broker"

Config Files

Bugs and Enhancements

Change Log

FAQ

License

CGI2SAS

SAS Side


Previous

Next


Overview
A CGI request is sent to a SAS session by defining 2 CGI variables. _program and _service in your HTML form, or link.  "_program" is run in a SAS session for service "_service". All available environment variables on the web server are also passed to SAS.

The CGI SAS program can access the CGI variables via macro variables, or an SCL list. The name of the macro variables are identical to the CGI variables in the CGI request. In the case of the SCL list there is a named character entry for each CGI variable.

The CGI SAS program writes its output to a pre-allocated filename "_webout". Note: The normal rules of CGI programs apply. The first line must contain "content type : text/html" (or whatever mime type as applicable).  The second line must be blank. All subsequent lines contain the file being passed back to the web browser.

Program Types (_program)

Plain Text SAS code (.sas)
The program name is expected to be in the format filename.obj.sas . Where :-
filename - pre-allocated "SAS filename". This filename must be allocated & authorised in the autoexec for the service.
obj - name of text SAS program in the directory pointed to by "filename"

For example:-
_program=fred.myprod.sas

In the autoexec.sas for the service
filename fred "c:\sascode";
%auth(filename=fred);

So program c:\sascode\myprod.sas would be executed.


SCL code
The program name is expected to be the fully qualified SCL name as you would use with the "call display" SCL function.

For example:-
_program=mylib.mycat.mycgi.scl

One parameter is passed to the SCL list. The listid of a SCL list containing all the CGI and environment variables.

SAS Code saved as .source catalog entry
The program name is expected to be the fully qualified SOURCE name.

For example:-
_program=mylib.mycat.mycgi.source


CGI Variables
All CGI variables & environment variables are created as
  • Macro variables
  • An SCL list passed as a parameter to SCL programs
All variables prefixed with _ (underscore) are considered to be reserved for the
use of CGI2SAS. I do no explicit checking (currently) however.

Current reserved variables
_service  - Name of service to connect to (as defined in CGI2SAS.CONF)
_program - Name of CGI program in SAS. The following forms are allowed.

Unsafe Variable Values
The values assigned to the macro variables and the scl list passed to .scl programs are striped of "unsafe" characters. The UNSAFE characters are defined in "threadmgr.conf"


Rather than navigating down the SCL lists, the unsafe values can be obtained in an
SCL program by using the AF_GETV macro.


%af_getv - Get a CGI variable (SCL Only)

This macro is designed to be used by .scl programs only. Either add the SAS folder in the
CGI2SAS install directory to your "sasautos", or submit the macro to SAS prior to compling your SCL code.

Parameters :
Name
Description
var
Name of the CGI or environment variable. The name must be enclosed in quotes, or be a SCL character variable containing the name of the CGI variable.
type
Type of variable to retrieve.
cgi - Get the CGI variable value
env - Get the Env variable value

Default - type=cgi
safe
Get the "safe" value
y - get the safe value
n - get the unsafe value

Default safe=y


Example:
value=%af_getv('myvar',safe=n);
put "Unsafe value of MYVAR is " value;


This will obtain the "unsafe" value of CGI variable myvar


%ds_getv - Get a CGI variable (Submitted SAS Code)

This macro is intended to be used to obtain unsafe values for CGI and environment variables. For consistancy it supports the same parameter calls as AF_GETV. %ds_getv & %getv are designed to be used outside a data step.

This macro is a performance hog. I dont know how to access SCL lists (where the unsafe values live) from SAS/Base so to get round this problem this macro calls an SCL program to
copy the CGI and envrionment variables into two datatsets work.__env and work.__cgi.

Another macro is made available as this point %getv, this macro can be used to obtain the unsafe values.


Parameters - %ds_getv:
None

Parameters - %getv:
Name
Description
newvar
Name of the macro variable to assign value to.
var
Name of the CGI or environment variable.
type
Type of variable to retrieve.
cgi - Get the CGI variable value
env - Get the Env variable value

Default - type=cgi
safe
Get the "safe" value
y - get the safe value
n - get the unsafe value

Default safe=y

Example:
%ds_getv;

%getv(newvar,myvar,safe=n,type=cgi);

data _null_;
  a=symget('newvar');
  put "Unsafe value of MYVAR is " a;
run;

Hints:
Using SYMGET to transfer a variable bypass's any quoting issues. Be VERY careful with your quoting if using unsafe values via macros.

Reserved librefs and filerefs
c2s_mac FILENAME CGI2SAS system macro library.
c2s_lib LIBNAME CGI2SAS system catalog library.
c2s_tmp LIBNAME System library for the SAS process. Parameter files etc

System Datasets

c2s_tmp.auth_cgi

Field Name
Type
Description
type
char(1)
Type of library.
F= Filename
L = Libname
ref
char(32)
Authorised libref or fileref of CGI program library
path
char(1024)
Full pathname of CGI program library




cgi2sast.parms

Field Name
Type
Description
name
char(32)
Name of parameter
value
char(1024)
Value of parameter




SCL Lists

The local environment list, as returned by envlist('l') function, contains a named list CGI2SAS. This SCL list contains the following sub-lists

Name
Description
parms
System parameters
auth_lib
Authorised CGI program LIBNAMES
auth_fn
Authorised CGI program FILENAMES
allcgi
All the CGI and envrionment variables. This list is also passed to the CGI .scl programs as arg{1}
cgi
Just the CGI variables
env
Just the CGI environment variables
unsafecgi
As the "cgi" scl list, except the "raw" cgi data (ie unsafe'd)
unsafeenv
As the "env" scl list, except the "raw" env data (ie unsafe'd)