Your SAS programs, embedded in web apps and elsewhere

How do I control what a SAS Stored Process returns when there is a stored process error?

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

How do I control what a SAS Stored Process returns when there is a stored process error?

I have a complex application that uses SAS stored processes called using Ajax. If the stored process works properly then we will stream a JSON message to the browser which we can pick up and determine whether the function of the stored process was a success or failure, as well as other information included in the JSON message. However if the stored process has an error, then we get a bunch of HTML streamed back along with the "show SAS log" button etc. I would like to override what the stored process web application is doing here and I would rather it just returned a JSON message saying that it had failed or something similar. Is there a way to override this? I'd appreciate any ideas/suggestions/answers. thanks, Phil Mason

p.s. We are using SAS 9.1.3 SP4 with Tomcat on a Windows server.


Accepted Solutions
Solution
‎12-01-2011 08:05 AM
Contributor
Posts: 22

How do I control what a SAS Stored Process returns when there is a stored process error?

Below is some code that shows how to solve this, thanks to Dimitri Woei.

%stpbegin ;

* this works ;
proc print data=sashelp.class ;
run ;
%put syserr=&syserr;

* this fails ;
proc errorintheprocname data=sashelp.class ;
run ;
%put syserr=&syserr;

* this wont run since there was an error ;
data _null_;
  a=1;
run;
%put syserr=&syserr;

* this also wont run ;
proc print data=sashelp.class ;
run;
%put syserr=&syserr;

%stpend ;

/* Add the below code at the bottom of your stored process. */
/* If an error occurs, then your customized error message   */
/* will be displayed in the HTML output.                    */
/* The "Show SAS log" button will not be displayed.         */

%macro checkcc;
options obs=max no$syntaxcheck;
%if (&syscc gt 4) %then %do;
data _null_;
  file _webout;
  put "<p><h3>Sorry, your request was not processed successfully.<h3>";
  rc = stpsrvset('program error', 0);
run;
%end;

%let syscc=0;
%mend checkcc;

%*** To see the difference try running this with the following line commented out, and then uncommented ;
%checkcc;

View solution in original post


All Replies
Regular Contributor
Regular Contributor
Posts: 166

How do I control what a SAS Stored Process returns when there is a stored process error?

Hi,

Not sure if i can be of much help here...

We used to create our own error messages for our stored processes in sas 9.1.on Unix environment.

To hide the log we used the Debug mask by creating a hidden prompt and setting the value _debug = 0

Then i think the stperror macro gave the information if there was an error in the processes and based on the return codes that sas generated we used to customise the output that was shown to the user.

Will this be of any help...

Solution
‎12-01-2011 08:05 AM
Contributor
Posts: 22

How do I control what a SAS Stored Process returns when there is a stored process error?

Below is some code that shows how to solve this, thanks to Dimitri Woei.

%stpbegin ;

* this works ;
proc print data=sashelp.class ;
run ;
%put syserr=&syserr;

* this fails ;
proc errorintheprocname data=sashelp.class ;
run ;
%put syserr=&syserr;

* this wont run since there was an error ;
data _null_;
  a=1;
run;
%put syserr=&syserr;

* this also wont run ;
proc print data=sashelp.class ;
run;
%put syserr=&syserr;

%stpend ;

/* Add the below code at the bottom of your stored process. */
/* If an error occurs, then your customized error message   */
/* will be displayed in the HTML output.                    */
/* The "Show SAS log" button will not be displayed.         */

%macro checkcc;
options obs=max no$syntaxcheck;
%if (&syscc gt 4) %then %do;
data _null_;
  file _webout;
  put "<p><h3>Sorry, your request was not processed successfully.<h3>";
  rc = stpsrvset('program error', 0);
run;
%end;

%let syscc=0;
%mend checkcc;

%*** To see the difference try running this with the following line commented out, and then uncommented ;
%checkcc;

Regular Contributor
Regular Contributor
Posts: 166

How do I control what a SAS Stored Process returns when there is a stored process error?

This is great.... Had been looking for something like this..Smiley Happy

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 668 views
  • 0 likes
  • 2 in conversation