SAS 9.1.3 Integration Technologies » Developer's Guide


SAS BI Web Services

Sample PROC MEANS Using SAS BI Web Services

The following sample shows how to write, define, and invoke a sample stored process that can be used with SAS BI Web Services.


Write the Stored Process

The following SAS code is a sample stored process called stpwsmea.sas. This program is installed with SAS Integration Technologies; by default it is located in C:\Program Files\SAS\SAS 9.1\inttech\sample.

   %put &tablename;

   libname _WEBOUT xml xmlmeta = &_XMLSCHEMA;
   libname instream xml;

   proc means data=instream.&tablename;
      output out=_WEBOUT.mean;
   run;

   libname _WEBOUT clear;
   libname instream clear;

Define the Metadata

The stored process must be defined in a SAS Metadata Repository that is used by SAS BI Web Services to determine how and where to run the stored process. Stored process metadata is defined using BI Manager. The tables in this section show the values for each field in BI Manager.

Note: If you have previously installed the SAS Stored Process sample metadata as part of the SAS Configuration Wizard or the Web Infrastructure Kit installation, you might not need to re-create the metadata for the "Sample: MEANS Procedure Web Service" sample stored process. The sample metadata should already be available from the Samples\Stored Processes folder in BI Manager. If you do not have the sample metadata, you can define the metadata for the stored process on your SAS Metadata Server using the following steps.

  1. Open SAS Management Console and connect to the appropriate metadata repository.

  2. From the SAS Management Console navigation tree, select the folder under BI Manager in which you would like to create the new stored process. (If you would like to first create a new folder, you can select the location in the navigation tree in which you want to add the new folder, and then select Actions arrow New Folder from the menu bar to open the New Folder Wizard. Follow the wizard instructions to create the new folder.)

  3. After you select the folder in which you want to add a new stored process, select Actions arrow New Stored Process from the menu bar. The New Stored Process Wizard displays.

  4. In the Name window of the New Stored Process Wizard, enter the following values in their corresponding fields for the sample Web service:

    Field Value
    Name Sample: MEANS Procedure Web Service
    Keywords XMLA Web Service

    Note: To add the keyword, click Add to open the Add Keyword dialog box, then enter the name of the keyword. Click OK to return to the Name window.

    Using the Name window to add a description for the stored process is optional.

  5. Click Next to go to the Execution window.

  6. In the Execution window of the New Stored Process Wizard, enter the following values in their corresponding fields for the sample Web service:

    Field Value
    SAS server Main - Logical Stored Process Server
    Source code repository C:\Program Files\SAS\SAS 9.1\inttech\sample
    Source code file stpwsmea.sas
    Output Streaming

  7. In the Execution window of the New Stored Process Wizard, click Streams to open the Input Stream Details window. Then click Add to open the Add Input Stream dialog box, where you must define the input stream. In this example, the input stream is named instream. Click OK to save the input stream definition.

    Note: You must also select the Supports multi-pass reads check box in the Add Input Stream dialog box. Otherwise, an XMLMap would need to be specified on the XML LIBNAME statement to define the XML schema for instream.

  8. Click OK in the Streaming Details window to return to the Execution window; then click Next to open the Parameters window.

  9. In the Parameters window of the New Stored Process Wizard, click Add to open the Add Parameter window. In the Add Parameter window, enter the following values in their corresponding fields for the sample Web service:

    Field Value
    Label tablename
    SAS variable name tablename
    Boolean properties Modifiable, Visible, and Required (are selected)
    Type String
    Default value InData

  10. Click OK to return to the Parameters window.

  11. Review your stored process information and click Finish to define the metadata for the stored process.

Invoke the Stored Process

SOAP Request

The stored process we just created can be invoked by SAS BI Web Services for Java and .NET middle-tier clients. A Web service client invokes the middle-tier Web service with an Execute() command. The SOAP request body, or client code, follows:

   <soap-env:Body>
      <Execute>
         <Command>
            <StoredProcess
               name="/Samples/Stored Processes/Sample:
               MEANS Procedure Web Service">
               <Parameter name="tablename">InData</Parameter>
               <Stream name="instream">
                  <Table>
                     <InData>
                        <Column1>1</Column1>
                        <Column2>20</Column2>
                        <Column3>99</Column3>
                     </InData>
                     <InData>
                        <Column1>50</Column1>
                        <Column2>200</Column2>
                        <Column3>9999</Column3>
                     </InData>
                     <InData>
                        <Column1>100</Column1>
                        <Column2>2000</Column2>
                        <Column3>1000000</Column3>
                     </InData>
                  </Table>
               </Stream>
            </StoredProcess>
         </Command>
         <Properties>
            <PropertyList>
               <DataSourceInfo>Provider=SASSPS;</DataSourceInfo>
            </PropertyList>
         </Properties>
      </Execute>
   </soap-env:Body>

SOAP Response

After you run the client code, the resulting SOAP response body is as follows:

   <soap-env:Body>
      <ExecuteResponse>
         <return>
            <root>
               <TABLE>
                  <MEAN>
                     <_TYPE_> 0 </_TYPE_>
                     <_FREQ_> 3 </_FREQ_>
                     <_STAT_> N </_STAT_>
                     <COLUMN3> 3 </COLUMN3>
                     <COLUMN2> 3 </COLUMN2>
                     <COLUMN1> 3 </COLUMN1>
                  </MEAN>
                  <MEAN>
                     <_TYPE_> 0 </_TYPE_>
                     <_FREQ_> 3 </_FREQ_>
                     <_STAT_> MIN </_STAT_>
                     <COLUMN3> 99 </COLUMN3>
                     <COLUMN2> 20 </COLUMN2>
                     <COLUMN1> 1 </COLUMN1>
                  </MEAN>
                  <MEAN>
                     <_TYPE_> 0 </_TYPE_>
                     <_FREQ_> 3 </_FREQ_>
                     <_STAT_> MAX </_STAT_>
                     <COLUMN3> 1000000 </COLUMN3>
                     <COLUMN2> 2000 </COLUMN2>
                     <COLUMN1> 100 </COLUMN1>
                  </MEAN>
                  <MEAN>
                     <_TYPE_> 0 </_TYPE_>
                     <_FREQ_> 3 </_FREQ_>
                     <_STAT_> MEAN </_STAT_>
                     <COLUMN3> 336699.333 </COLUMN3>
                     <COLUMN2> 740 </COLUMN2>
                     <COLUMN1> 50.3333333 </COLUMN1>
                  </MEAN>
                  <MEAN>
                     <_TYPE_> 0 </_TYPE_>
                     <_FREQ_> 3 </_FREQ_>
                     <_STAT_> STD </_STAT_>
                     <COLUMN3> 574456.555 </COLUMN3>
                     <COLUMN2> 1094.89726 </COLUMN2>
                     <COLUMN1> 49.5008417 </COLUMN1>
                  </MEAN>
               </TABLE>
            </root>
         </return>
      </ExecuteResponse>
   </soap-env>