SAS 9.1.3 Integration Technologies » Developer's Guide


SAS Stored Processes
Software Requirements
Creating Stored Processes
Input Parameters
Result Types
%STPBEGIN and %STPEND
Reserved Macro Variables
Stored Process Server Functions
Sessions
Samples
Debugging
Converting SAS/IntrNet Programs
Using Stored Processes
Building a Web Application
SAS Stored Process Web Application
Configuration
Input
HTTP Headers
Embedding Graphics
Chaining Stored Processes
Using Sessions
Debugging
IOM Direct Interface Stored Processes
SAS Stored Processes

Stored Process Samples

The following samples demonstrate how a stored process generates different types of output using the %STPBEGIN and %STPEND macros. All of the samples are based on the following stored process:

   *ProcessBody;
   %STPBEGIN;
      title 'Age analysis by sex';
      footnote;
      proc sort data=sashelp.class out=class; by sex age; run;
      proc gchart data=class;
         vbar3d age / group=sex
            discrete
            nozero
            shape=cylinder
            patternid=group;
      run; quit;
      title;
      proc print data=class;
         by sex age;
         id sex age;
         var name height weight;
      run;
   %STPEND;

This code generates a bar chart and a table. The exact format and appearance of the output depends upon various input parameters. For these samples, assume the following input parameters were specified:

Variable Value Comments
_ODSDEST HTML Default destination. Not required.
_ODSSTYLE SASWeb  
_GOPT_DEVICE ActxImg Generates a PNG image file. Available only on Windows platforms.
_GOPT_XPIXELS 384 Image width in pixels
_GOPT_YPIXELS 288 Image height in pixels

Note: See the section on Reserved Macro Variables for a more detailed description of each macro variable mentioned in the previous table and in the following sections.

Streaming Output

Streaming output is generally used when you are executing a stored process from a Web-based application using the SAS Stored Process Web Application or when you are returning a single output file with no embedded links to companion files such as images. Because the stored process was registered with a result type of Streaming, the following input parameters are passed to the stored process:

Variable Value
_RESULT STREAM
_ODSDEST HTML
_ODSSTYLE SASWeb
_GOPT_DEVICE ActxImg
_GOPT_XPIXELS 384
_GOPT_YPIXELS 288

The HTML output from the stored process is streamed to the client though the server-created _WEBOUT fileref. The PNG image file is streamed through a separate replay connection to the server, as described in the section on Embedding Graphics.

Creating a Transient Package

Transient packages are a convenient way to deliver a collection of multiple output files to a client application. Transient packages are implemented in different ways for the stored process server and the workspace server as described in the following sections.

Stored Process Server

A stored process registered with a result type of Transient result package on a stored process server is executed with _RESULT set to PACKAGE_TO_ARCHIVE and _ARCHIVE_PATH set to TEMPFILE. The input parameters are as follows:

Variable Value
_RESULT PACKAGE_TO_ARCHIVE
_ARCHIVE_NAME TEMPFILE
_ODSDEST HTML
_ODSSTYLE SASWeb
_GOPT_DEVICE ActxImg
_GOPT_XPIXELS 384
_GOPT_YPIXELS 288

Workspace Server

The same stored process registered on a workspace server is executed with _RESULT set to PACKAGE_TO_REQUESTER and no value for _ARCHIVE_PATH. The input parameters are as follows:

Variable Value
_RESULT PACKAGE_TO_REQUESTER
_ODSDEST HTML
_ODSSTYLE SASWeb
_GOPT_DEVICE ActxImg
_GOPT_XPIXELS 384
_GOPT_YPIXELS 288

Creating a Permanent Package Archive

Permanent packages are published to a permanent location where they can be accessed at a later time. Permanent packages are also immediately available to the stored process client through the same interfaces used for a transient package. This sample assumes that the stored process was registered with the following metadata, in addition to the parameters already listed:

Metadata Field Value
Output type Permanent result package
File system Selected
Archive path c:\My Packages
Archive name AgeAnalysis.spk

Again, implementation differs between the stored process server and the workspace server. _RESULT is set to PACKAGE_TO_ARCHIVE or PACKAGE_TO_REQUESTOR, respectively. The input parameters are as follows:

Variable Value
_RESULT PACKAGE_TO_ARCHIVE or PACKAGE_TO_REQUESTER
_ARCHIVE_PATH C:\My Packages
_ARCHIVE_NAME AgeAnalysis.spk
_ODSDEST HTML
_ODSSTYLE SASWeb
_GOPT_DEVICE ActxImg
_GOPT_XPIXELS 384
_GOPT_YPIXELS 288

The archive package is created at C:\My Packages\AgeAnalysis.spk, and the variable _ARCHIVE_FULLPATH is set by %STPEND.

Creating a Permanent Package on a WebDAV Server

Permanent packages can also be published to WebDAV servers by specifying the appropriate options when registering the stored process. This sample assumes that the stored process was registered with the following metadata, in addition to the parameters already listed:

Metadata Field Value
Output type Permanent result package
DAV location Selected
Server http://server1.abc.com/
Base path /dav
Base path /reports
Create new instance Selected

The input parameters are as follows:

Macro Variable Name Value
_RESULT PACKAGE_TO_WEBDAV
_PARENT_URL http://server1.abc.com/dav/reports
_ODSDEST HTML
_ODSSTYLE SASWeb
_GOPT_DEVICE ActxImg
_GOPT_XPIXELS 384
_GOPT_YPIXELS 288

The package is created in a uniquely named collection under http://server1.abc.com/dav/reports.

Publishing a Package to E-Mail

As discussed in the section on Advanced Package Publishing, packages can be published to other destinations with minor modifications to the stored process. Adding two lines to the stored process such as

   *ProcessBody;
   %let _RESULT=PACKAGE_TO_EMAIL;
   %let _ARCHIVE_PATH=TEMPFILE;
   %STPBEGIN;
      title 'Age analysis by sex';
      footnote;
      proc sort data=sashelp.class out=class; by sex age; run;
      proc gchart data=class;
         vbar3d age / group=sex
            discrete
            nozero
            shape=cylinder
            patternid=group;
      run; quit;
      title;
      proc print data=class;
         by sex age;
         id sex age;
         var name height weight;
      run;
   %STPEND;

and registering the stored process with None as the result type enables you to publish a package to e-mail addresses. Additional input parameters specify the e-mail address, a subject line, and a reply-to address, as follows:

Variable Value
_RESULT STATUS (is modified in the stored process)
_EMAIL_ADDRESS DeptManagers@abc.com
_REPLYTO ReportAdmin@abc.com
_SUBJECT Age Analysis Report
_ODSDEST HTML
_ODSSTYLE SASWeb
_GOPT_DEVICE ActxImg
_GOPT_XPIXELS 384
_GOPT_YPIXELS 288

The package is created and mailed to the DeptManagers@abc.com address. If you make slight modifications to the input parameters, then you can publish the package to a WebDAV location and mail a reference to the package to one or more e-mail addresses.