SAS Support
Self Service Support
Assisted Support
Premium Support
Infrastructure Support
Logging a Call
Service Levels
Hints and Tips
 

THE SAS® STORED PROCESS - UNLEASHING THE POWER OF SAS

We all know that SAS delivers fast and accurate forecasts. Many of you get forecasts on demand from a SAS interface such as SAS Enterprise Guide, the SAS Information Delivery Portal or Display Manager. The true power of SAS is unleashed when these results are reviewed and acted on by the right people at the right time.

But of course there are more and more of the "right people". With the business benefits of forecasting and optimisation now widely accepted, this has fuelled the demand for wider access to such processes - and it's not just people, either.

Imagine, for example, the benefits of a supply chain management system that automatically requests a forecast on stock levels if an order reduces holdings of a product to less than half. Or a credit risk management system that triggers fraud analysis of certain banking transactions. In such cases the systems don't want a report, printable or otherwise: they want data in a form they can process. Whether we need to deliver results to a person or a system, what we're trying to achieve is a service that returns results in the right form to the requester.

Enter the SAS Stored Process, one of the most powerful new tools in the SAS®9 architecture. It's a SAS program that is stored on a server and registered in metadata. And it will do pretty much anything: you're only limited by what you know about the SAS language and the SAS modules you have. It could be 10,000 lines of code or 10, it could be DATA and PROC steps or SQL. It could be calling a complex optimisation routine or a simple print, and what it returns could be PDF, HTML or XML or any other output format that SAS supports.

SAS® Stored Processes SAS Stored Processes can be accessed in a number of ways. SAS clients such as SAS Enterprise Guide, SAS Web Report Studio, the Add-In for Microsoft Office and the SAS Information Delivery Portal can call stored processes automatically. They have interfaces that will search the metadata server and present lists of available stored processes to the user. SAS Stored Processes developed for this purpose typically have a structure as follows:


*ProcessBody;

%stpbegin;

proc print data=SASHELP.CLASS;

run;

%stpend;

The comment is required as it defines the separator between the prologue and the process body. The two macros ensure the correct ODS options are applied according to the requesting client: it will apply ODS HTML if the calling client is a web interface and ODS RTF if the calling client is MS Word, and so on. See http://support.sas.com/documentation/cdl/en/stpug/62758/HTML/default/viewer.htm#n0nsj5vk0huz6yn15ohrpmwk2812.htm.

Adding user-defined parameters will enhance these stored processes. For instance, in the previous example we might want the user to define gender:


%global gender;

*ProcessBody;

%stpbegin;

proc print data=SASHELP.CLASS;

where sex="&gender";

run;

%stpend;

Web applications SAS Stored Processes can also be invoked from web clients by calling the Stored Process Web application. The URL might look like:
http://web-server:portnumber/SASStoredProcess/do?_program=/BIP_Tree/Reports/students&gender=M

The stored process itself will probably look like:


%global gender;

ODS HTML file=_webout;

proc print data=SASHELP.CLASS;

  where sex="&gender";

run;

ODS HTML close;

In a simple stored process like this, you could still use the %stp macros. Stored Process Web applications are often chained together, such that the first stored process presents a HTML form for the user to select the parameters, and then links to a second stored process that generates the results. In these cases it's often preferable to use ODS as it offers more flexibility and the developer is less concerned about the type of client that's making the request. Special macro variables are available within the web application to allow session management (maintaining state between calls) that can be important for efficiency. Some understanding of HTML is helpful in these cases but ODS hides much of the complexity.

You can find more examples of Stored Process Web Applications at:
http://support.sas.com/documentation/cdl/en/stpug/62758/HTML/default/viewer.htm#datapass.htm

Web Services
A stored process can also be seen as an important part of Web Services, which in turn are part of the Service Oriented Architecture (SOA). Put simply, Web Services enable applications written in various programming languages to communicate using a standard web-based protocol, typically the Simple Object Access Protocol (SOAP). This makes it possible for organisations to bridge the gaps between different applications and systems. SAS supports both the .NET framework and Java.

The standard ensures a client can find out which service it should use and which parameters it needs to send to use that service, and then call the service and get the results back in a form it can use. This is implemented by allowing two method calls: discover() and execute(). These methods will send XML contained within a SOAP envelop and receive results in the same form. The stored process itself will likely look like this:


%global gender;

libname _WEBOUT xml xmlmeta=&_XMLSCHEMA;

data _WEBOUT.table;

set SASHELP.CLASS;

where sex="&gender";

run;

libname _WEBOUT clear;

The first LIBNAME statement ensures the output is streamed back to the caller as XML and the right content is sent back by using the _XMLSCHEMA macro. The rest of the process should be familiar to any SAS programmer. The XML is complex but you are shielded from this complexity by SAS Web Services and can replace the simple DATA step in this example to any SAS process or procedure you want to surface to the business. It's worth noting that a Web Services stored process can also receive data to process via a stream, so in this next example the data sent from the requester is used in a MEANS procedure and the results streamed back:


libname instream xml;

libname _WEBOUT xml xmlmeta=&_XMLSCHEMA;

proc means data=instream.&tablename;

  output out= _WEBOUT.table;

run;

libname _WEBOUT clear;

libname instream clear;

Summary
It's clear that your investments in SAS can be greatly enhanced by providing the benefits of optimisation and forecasting to every part of the business - and that can be enabled in part by the powerful new interfaces in the SAS Business Intelligence Server Solution. The Stored Processes, however, extend the capability into all areas of the business.

Note: SAS Stored Processes is only available as part of SAS Integration Technology, Business Intelligence Server or Enterprise Business Intelligence Server. Service Oriented Architectures and Web Services will be covered in more detail in a future edition of In The Know.


Did you find this page useful?

If you have any comments or questions, feel free to contact us.




0845 402 9907