Monday, January 11, 2010

A simple Stored Process to run any Macro

OK. OK. OK. I know I have been negligent is posting the details about this. But I am still trying to wrap my head around doing things in tiny bits and pieces. I promise I will do better from now on ;-)!

In my last post I talked about creating a simple stored process that could be used to run any macro. So, for example, if you had lots of reports and wanted to make them avaiable from the Stored Process Server you need not create a distinct stored process for each one.

Create a stored process in an appropriate folder (more on this in later posts) and define the following three parameters:
  1. macroToRun: the name of the macro that is to be run. Make this a required parameter.
  2. _odsDest: the ODS Destination (e.g., HTML, PDF, RTF, and so on). Make this a required parameter and give it a default value.
  3. _odsStyle: the ODS Style to use. This is an optional parameter as SAS will use a default style if not specified.
Now, create a sas program as the source for your stored process. Here is a simple version to get you started:

*ProcessBody;
%stpBegin;
%put NOTE: Execute macro &macroToRun..;
%&macroToRun
%stpEnd;

When this stored process is executed any values provided in the HTML form or hyperlink are available to the stored process and, thus, to the macro code. So presuming you specify myReport as the value of macroToRun, the SAS wordscanner will parse

%&macroToRun

and resolve it to:

%myReport

which will run your report macro assuming the path where it is located is defined to the Stored Process Server (and that will be the subject of an upcoming post).