Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Syntax for SAS Stored Process

Tags:

sas

I am trying to complete the example on page 19 of the SAS BI Web Services Developers Guide. I have followed the instructions verbatim but am unable to get the stored process (automatically a web service) to return the correct result when I make a post request. I am trying both SOAP and XML. The error is that the 'instream' data source is never found.

What I am asking for is for someone to replicate the example and give the exact XML and/or SOAP with the post request (in the form of curl).

Here is the SOAP (straight from the guide)

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:sas="urn:schemas-microsoft-com:xml-analysis">
<soapenv:Header/>
<soapenv:Body>
<sas:Execute>
<sas:Command>
<StoredProcess name="/WebServicesExamples/sampMeans">
<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>
</sas:Command>
<sas:Properties>
<PropertyList>
<DataSourceInfo>Provider=SASSPS;</DataSourceInfo>
</PropertyList>
</sas:Properties>
</sas:Execute>
</soapenv:Body>
</soapenv:Envelope>

I am posting via curl. Here is my curl command

curl -H "Content-Type: text/xml" -X POST https://mycompany.com:port/SASBIWS/services/WebServicesExamples/sampMeans --data "@sampmeanssoap.xml"

But this produces the error

A 'Client' type of exception occurred during execution of 'WebServicesExamples/sampMeans' service. The exception follows: Expected stream 'instream' was not specified.

XML produces a similar response

<StoredProcess name="/WebServicesExamples/sampMeans">
 <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>

With curl

curl -H "Content-Type: text/xml" -X POST https://mycompany.com:port/SASBIWS/rest/storedProcesses/WebServicesExamples/sampMeans --data-binary "@sampmeanssoap.xml"

I can successfully get stored processes to complete when using only parameters but am unable to send data sources for whatever reason.

like image 641
Ted Petrou Avatar asked Sep 26 '22 23:09

Ted Petrou


People also ask

How do I create a stored process in SAS?

To create a stored process using the SAS code from a program or task, right-click on the program item or task item, and select Create Stored Process. To create a stored process using the SAS code from a process flow, right-click in the process flow and select Create Stored Process.

What are SAS stored processes?

A stored process is a SAS program that is stored on a server and can be executed as required by requesting applications. You can use stored processes for Web reporting, analytics, building Web applications, delivering packages to clients or to the middle tier, and publishing results to channels or repositories.

What is a SAS stored process and how can you execute one?

based on that task. A SAS stored process is a SAS program that is hosted on a server and described by metadata. A stored process can be invoked by many of the new clients in the SAS®9 Intelligence Platform.


1 Answers

Finally found an answer and posted it to SAS communities as well (https://communities.sas.com/t5/SAS-Stored-Processes/Help-with-XML-Syntax-for-post-request-to-Stored-Process/m-p/239032/highlight/false#M3304)

Unfortunately the documentation is sorely lacking of concrete examples of sending streams of data through plain XML. I was initially trying to just insert the plain XML part of the lone example SOAP request in the XMLA part of the documentation but my stream 'instream' was unable to be located.

The key to the solution was to look at the wsdl file (just append ?wsdl to the endpoint. ex: https://mycompany.com:port/SASBIWS/services/path/to/process/process_name?wsdl) I had gotten a simple addint stored process to return successfully and noticed that in my new stored process that the wsdl did not match the example in the developers guide. Here is the pertinent part of the wsdl for the stored process that streamed data.

<xsd:complexType name="upload_stream5Streams">
<xsd:sequence>
<xsd:element name="instream">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Value">
<xsd:complexType>
<xsd:sequence>

I needed separate elements for streams, instream, and Value, which is absolutely nowhere across the internet as far as I know.

Here is the complete XML

<upload_stream5>
<streams>
<instream>
<Value>
<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>
 </Value>
 </instream>
</streams>
</upload_stream5>

And here is the actual stored process sas code. Its a bit different than the developer's example because there is no _XMLSCHEMA macro variable. (tablename is defaulted to InData but you can pass this with XML as well using <parameters> and <parameter_name> tags)

%put &tablename;
libname otstream xml xmlmeta = SchemaData;
libname instream xml;
proc means data=instream.&tablename;
 output out=otstream.mean;
run;
libname otstream clear;
libname instream clear;
like image 131
Ted Petrou Avatar answered Oct 18 '22 01:10

Ted Petrou