Getting Data and Files into and Out of Stored Processes

Input Files

A stored process can accept input in the form of an input file. An input file is a SAS fileref that is set up before the stored process begins execution. The fileref can point to a local file on the server, a stream fed by the client, a temporary file written by the client, or any other valid fileref that is set up by a stored process client.
Input files are identified by a unique fileref name and are defined in the stored process metadata. The metadata can provide descriptive information or hints to guide clients in the use of input files. Input files can be optional or required. Input files are not assigned if the client does simply corresponding input.

Input Data

SAS programs frequently process input data sets. An input data set is defined by a macro variable that contains the data set name. Any setup required to access the data set (typically a libref assignment) is handled by the stored process framework.
The following code is an example of a stored process with an input data set named SALESDATA:
%stpbegin;
 
title "Sales for &MONTH, &YEAR";
proc print data=&SALESDATA
  where Month eq "&MONTH" and Year eq &YEAR
  var productid product sales salesgoal;
  run;
 
%stpend;
Different stored process client APIs provide different mechanisms for supplying input data sets to a stored process, including:
Server data sets
specifies that the macro variable is set to the two-level data set name and, if necessary, the required libref is assigned.
Client data sets
specifies that the client data set is copied to the WORK library on the server system and the macro variable is set to the temporary data set name.
XML data
specifies an XML file or data stream as input data to the stored process. The XML data is passed to the stored process via a temporary file and an XML engine libref is assigned to the temporary file. The client can specify an XML map to describe the format of the XML.
Client API access
specifies direct data access APIs that are appropriate for the technology (for example, a JDBC connection for a Java API.)

Output Files

A stored process can create output in the form of an output file. An output file is a SAS fileref that is set up before the stored process begins execution. The fileref can point to a local file to be created on the server, a stream consumed by the client, a temporary file that is read by the client after execution is complete, or any other valid fileref that is set up by a stored process client.
Output files are identified by a unique fileref name and are defined in the stored process metadata. The metadata can provide descriptive information or hints to guide clients in the use of output files. Output files can be optional or required. Optional output files are not assigned if the client does not request the output.
The _WEBOUT fileref is frequently used for streaming output from a stored process. The client API can assign the _WEBOUT fileref to a server local file, a temporary file, or any other valid fileref. In the streaming output use case, _WEBOUT is assigned to a stream using the CACHE access method. Then ODS is configured to write to _WEBOUT, and a handle to the _WEBOUT stream is returned to the client Web application. The client Web application can read output from the stream as it is written by the stored process.

Output Data

Stored processes support the generation of output data sets. An output data set is defined by a macro variable that contains the data set name. Any setup required to access the data set (typically a libref assignment) is handled by the stored process framework.
The following code is an example of a stored process that generates an output data set named SCORING:
%stpbegin;
 
data &SCORING;
  set MYLIB.RAWDATA;
  score = /* insert scoring algorithm based on input parameters here */;
  run;
 
%stpend;
Different stored process client APIs provide different mechanisms for accessing output data sets, including:
Server data sets
specifies that the macro variable is set to the two-level data set name and, if necessary, the required libref is assigned.
Client data sets
specifies that the macro variable is set to a temporary data set name in the WORK library on the server system. After execution is complete, the data set is copied to the client system.
XML data
assigns a temporary fileref and a corresponding XML engine libref. The macro variable is set to a table in the XML libref. After execution is complete, the resulting XML file is copied to the client system.
Client API access
specifies direct data access APIs that are appropriate for the technology (for example, a JDBC connection for a Java API.)