Writing SAS Programs for Structured Web Services

In general, SAS programs for structured Web services can use all the functionality supported by SAS Stored Processes.

Consuming Input in SAS Programs

SAS BI Web Services can provide input to your SAS programs by using filerefs and macro variables. Filerefs enable you to stream arbitrary content such as raw XML or binary files from your Web service client to be used in your SAS code. Filerefs can be associated to librefs if the content that you send (such as XML) can be read by a SAS LIBNAME engine. The stored process engine automatically assigns filerefs for your stored process data sources so you do not need to explicitly include a FILENAME statement in your SAS code. For example, the following SAS program snippet simply reads from the instream fileref and prints the contents to the SAS log:
data _null_;
	  infile instream;
	  INPUT;
	  PUT _INFILE_;
run;
No other SAS code is needed in this program; you have only to define a data source named instream in your stored process definition. See Using Attachments with Web Services for more information about how to define your stored processes so that you can supply input data to your SAS programs.
You can include macro variables in your SAS program, and SAS BI Web Services set these macro variables based on the parameters that you supply during Web service invocation. For example, you can use this simple SAS program as a stored process to add two numbers together:
%let sum = %sysevalf(&num1 + &num2);
Define prompts with the stored process metadata to enable the passing of parameters to macro variables. The prompting framework provides additional information about the type of input macro variable and allows for additional validation before execution. See Using Prompts with Generated Web Services for more information about defining prompts.

Retrieving Output Values from the SAS Program

You can use filerefs and macro variables as output just like you can with input. Output filerefs are automatically assigned by the stored process engine if the SAS code writes to the fileref. Expanding on the previous example, the following SAS program snippet copies from an input fileref to an output fileref:
data _null_;
	  infile instream;
	  file otstream;

	  INPUT;
	  PUT _INFILE_;
run;
Define the input data source instream and the output data target outstream in the stored process metadata. See Using Attachments with Web Services for more information about how to define your stored processes so that you can retrieve output data from your SAS programs.
In the following example, the value of the Sum macro variable is automatically retrieved by the stored process engine when you define an output parameter in the stored process metadata:
%let sum = %sysevalf(&num1 + &num2);
Output parameters are similar to prompts, but there are fewer types of output parameters.
Note: When using the JSON message format, you are limited to prompts that have a simple string representation for input and you can retrieve values only from stored process output parameters. You cannot supply any stored process data sources when invoking SAS BI Web Services using JSON. If your stored process outputs data targets, packages, or streams to _WEBOUT, you cannot access these resources when using JSON. Remember this when you author SAS programs that you intend to use with JSON.