Create a SAS Program File for a Stored Process


Overview of Writing Stored Processes

A stored process is a specialized SAS program file that is stored on a server. All SAS stored process code must conform to the following requirements:

  • The code must begin with the comment *ProcessBody;.
  • Any statements that produce streaming ODS output must be enclosed within the %stpbegin; and %stpend; statements.

Basic Example: Returning ODS Output

For example, the following code prints a data set:

*ProcessBody;
%stpbegin;
proc print data=sashelp.class;
run;
%stpend;

The streaming output appears in your default Web browser.


Retrieving Data Sets in a Stored Process

You can use the _WEBOUT fileref to request that ArcMap retrieve data sets. To send a data retrieval message, put a message with the following format to the _WEBOUT fileref: indicator-tag, libref.data-set. The indicator tag is a signal that identifies a data set request to Bridge for Esri. You can use the Data set indicator tag option in SAS Bridge for Esri to specify the tag value. For example, the following code uses the default data set indicator tag _SBFEds to return a SAS data set to ArcMap:

*ProcessBody;
%let myvar='_SBFEds, SASHELP.RETAIL';
data _null_;
file _webout;
put &myvar;
run;

SAS Bridge for Esri creates an OLE DB connection to retrieve the SASHELP.RETAIL data set. If the Show results in table of contents option is enabled, then the SASHELP.RETAIL data set appears on the Source tab of the Table of Contents pane in ArcMap.

Note the absence of the stored process macros %STPBEGIN and %STPEND. If you are using SAS Enterprise Guide to create this stored process, be sure to turn off the inclusion of stored process macros. For information about how to deselect the default inclusion of stored process macros, refer to the Help system that is provided with SAS Enterprise Guide.


Using Layer Data in a Stored Process

To receive layer data from ArcGIS, the stored process must create an XML libref with an XMLTYPE of GENERIC. For example:

libname instream xml xmltype=generic;

If you have created an XML libref for the ArcGIS data, then you can use the &Layer macro variable to refer to the layer that is selected in ArcMap. For example, the following code prints the selected label:

*ProcessBody;
%stpbegin;
libname instream xml xmltype=generic;
proc print data=instream.&Layer;
run;
%stpend;

More Information

For more information about writing stored processes, see the SAS Stored Processes Developer's Guide at http://support.sas.com/documentation/onlinedoc/inttech/index.html.