SAS® Stored Processes might execute multiple times when they are included in a scheduled SAS® Web Report Studio report


Overview
If a scheduled SAS Web Report Studio report includes a stored process, the stored process is executed at least four times when the report is generated at the scheduled time. The multiple executions occur because SAS Web Report Studio must create four static versions of the report:

An HTML version.
A PDF version.
A version for exporting to Microsoft Excel.
A version for opening the report using the SAS® Add-In for Microsoft Office and SAS® Enterprise Guide®.
These versions are created so that there is a static copy of the report available regardless of how the report is accessed. This is by design.

Consequences and Workarounds
Because four versions of the report are created, SAS Web Report Studio attempts to run the stored process four times. Depending on your stored process, you might encounter the following unexpected behavior.

If your stored process sends email, then the email is sent four times. There is no workaround that prevents the emails from being sent. If the stored process is the only content in the report, then consider using a different method of scheduling the stored process such as an operating system scheduler. (SAS Web Report Studio reports can be scheduled only from SAS Web Report Studio.)

If your stored process creates output data sets, some attempts to run the stored process might fail. You might see an error that a table is locked or that a library cannot be reassigned. For example, you might see an error in the SAS Web Report Studio log that is similar to this:

You cannot open WORK.MYLIB.DATA for output access with member-level control because WORK.MYLIB.DATA is
in use by you in resource environment IOM ROOT COMP ENV.


To avoid this problem, you can include the following SAS code in your stored process. This code checks for the existence of the SAS work table that is the output of the stored process. If the table exists, then the code is not run again.

*processbody;
/* **********************************************************************
*
*  Description: Checkit macro checks for the existence of the SAS table
*               that is going to be created in the stored process.  If
*               the table already exists, then the code is not run again.
* Note:  In the example below, the table SOURCEDATASET is the output
*        from the stored process. Change this value for your
*        output table. Also change the library (WORK) if necessary.
*********************************************************************** */
%let exist=0;
%macro checkit;
 data _null_;
   if exist('work.sourcedataset') then call symput('exist',1);
run;
%if &exist=0 %then %do;
 /* ADD YOUR SAS Code BELOW THIS LINE */
 %end;
 %mend;
%checkit;
run;