Writing SAS Programs for XMLA Web Services

To use the Web service to call your SAS code, you must configure your SAS code as a stored process. A stored process is a SAS program that is stored on a server and can be executed by requesting applications. Any stored process can be deployed as a generated Web service. However, stored processes that are used with XMLA Web services need to conform to rules that enable the Web service to receive data from the client and return data to the client.
You can author a stored process manually by using SAS or a text editor to write the code and then registering the program through SAS Management Console. Alternatively, you can use a program such as SAS Enterprise Guide or another SAS code generator to author a stored process using the point-and-click method. Use the following modifications to make a stored process that can be used with SAS BI Web Services. Keep in mind that XMLA Web services can return XML data only; no attachments can be returned.
Note: XMLA Web services in SAS 9.3 will work only with SAS 9.3 stored process metadata and SAS 9.3 Stored Process Servers.
The following list explains unique details about stored processes that are used with XMLA Web services:
  • The data that is returned by the stored process must be XML. Web service stored processes produce streaming results, which means that the SAS program writes output to _WEBOUT, typically by using the following LIBNAME statement:
    libname _WEBOUT xml xmlmeta=&_XMLSCHEMA;
  • For XMLA Web services, the %STPBEGIN or %STPEND macros are not used in the stored processes. These macros set up Output Delivery System (ODS) statements for the stored process, but XMLA Web services do not use ODS.
  • The _XMLSCHEMA macro is unique to XMLA Web services. This macro is passed to the SAS program when it is invoked from the Web service. The _XMLSCHEMA macro is set to one of three values depending on the Content property that gets passed to the Execute method. The possible values for _XMLSCHEMA are Schema, SchemaData (which is the default), Data, or None. For example, the following code causes SAS to write both the XML schema and the data into the libref _WEBOUT:
    libname _WEBOUT xml xmlmeta=SchemaData;
    A libref uses a fileref of the same name when a source is not specified in the LIBNAME statement. For example, the following code causes the libref, called _WEBOUT, to read from the fileref called _WEBOUT:
    libname _WEBOUT xml xmlmeta=_XMLSCHEMA;
    For XMLA Web services, SAS defines the filerefs for the _WEBOUT output stream as well as for any input streams before invoking the SAS code.
    Note: Applications should not try to write multiple data sets into a library when a schema is being created.
  • Data sources are defined when you are registering the stored process metadata. There are three types of data sources:
    • Generic streams, which are most similar to the input streams that were used before SAS 9.2.
    • XML streams, which can be described with or without a schema. If a schema is provided for an XML stream, then that schema is inserted in the WSDL for the service. If no schema is provided, then xs:any is inserted in the WSDL. Having a schema defined makes it easier for client applications to call a service. The SAS code needs to be written to create XML that is valid according to the schema that is defined in the metadata.
    • Data tables, which are new for SAS 9.3 and describe tabular input and output. Data tables cannot be used with XMLA.
The following example code displays a stored process that is used as a Web service:
libname instream xml;
libname _WEBOUT xml xmlmeta=&_XMLSCHEMA;

proc means data=instream.&tablename
   output out=_WEBOUT.mean;
run;
The first LIBNAME statement in the sample code defines the data source. This code corresponds to the definition of the data source in the Stored Process Properties dialog box in SAS Management Console. The fileref of the data source is instream. In this example, the data source provides the data to run PROC MEANS against.
The second LIBNAME statement in the sample code defines the output for the stored process as streaming output, or _WEBOUT. In the Stored Process Properties dialog box, Stream is specified as the type of output on the Execution tab of the Stored Process Properties dialog box.
The &tablename declaration in the sample code defines a parameter called tablename. In the Stored Process Properties dialog box, this parameter is specified through the New Prompt dialog box, and can be modified using the Edit Prompt dialog box. In this example, tablename is a text parameter that specifies the name of the table to run PROC MEANS against.
Note: The dialog boxes mentioned in the previous example are available from both the Stored Process Properties dialog box and the New Stored Process wizard, which are both part of SAS Management Console. For more information about using SAS Management Console to define metadata for stored processes, see the product Help.