BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Fluorite | Level 6

I have a series of stored processes that perform tasks are are called from a Web application via the Stored Process Web App.  I have error checking in the code and want to return a JSON string with error messages instead of the whole SAS log.  My web developers don't need to see the SAS log or to have to parse it.  They just need some basic information.


Found this which puts me on the right track, but it doesn't seem to work with PROC JSON.


My macro is as follows:

%macro status_output(_webout);
%let syserr=0;
%let syscc=0;

proc json out=&_webout pretty nosastags;
	write values "STATUS" "&rc";
	%if %sysevalf(&rc > 0) %then %do;
		write values "ERROR";
		write open object;
			write values "ERROR_MSG" "&ERROR_MSG";
			write values "ERROR_REASON" "&ERROR_REASON";
		write close;

However, when an error occurs, I still get the SAS Log and not my nice error handling.    


I do see this in the log:

7435      +%status_output(_webout);
MPRINT(STATUS_OUTPUT):   proc json out=_webout pretty nosastags;
MPRINT(STATUS_OUTPUT):   write values "STATUS" "1008";
MPRINT(STATUS_OUTPUT):   write values "ERROR";
MPRINT(STATUS_OUTPUT):   write open object;
MPRINT(STATUS_OUTPUT):   write values "ERROR_MSG" "In insert_variable - RC:1008";
MPRINT(STATUS_OUTPUT):   write values "ERROR_REASON" "Error Adding Variable - ORACLE: ORA-00001: unique constraint (IF_A2RPT.FACTOR_VARIABLES_UK1) violated;
MPRINT(STATUS_OUTPUT):   write close;

WARNING: RUN statement ignored due to previous errors. Submit QUIT; to terminate the procedure.NOTE: PROCEDURE JSON used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

There is no ERROR in PROC JSON, which leads me to believe it might be checking another system macro variable.


Curiously, if I execute the code from SAS Studio (writing to a different file than _webout), this run without problem and the file is populated beautifully.  This leads me to also believe there is something I can set to override the annoying behavior.


Anyone know what I need to do?


Accepted Solutions
Fluorite | Level 6



Which solved the problem.


If the error was severe enough for SAS to enter syntaxcheck mode, you would see a note in the log to that effect.  "SAS set obs=0 blah blah".  And no code after that will be excuted.


My guess is in SAS Studio syntaxcheck mode is off by default.


In the stored process server, you could turn off syntaxcheck with:

options nosyntaxcheck;

but there are risks to doing that (if you have an error in code and end up with a 0 obs dataset, it might overwrite other datasets with 0 obs).


I think the better approach is to have your error handling macro recover from syntaxcheck mode. You can recover with:

%* if obs=0 assume that means SAS is in syntaxcheck mode, so recover;
%if %sysfunc(getoption(obs))=0 %then %do;
  options obs=max replace NoSyntaxCheck;
Check out the Boston Area SAS Users Group (BASUG) video archives:
Fluorite | Level 6

Exactly what I did.  The output and PROC JSON is always the last step, so I just set NOSYNTAXCHECK without checking the status.  There is nothing else to worry about.  The stored process streams the JSON and exits.

Lapis Lazuli | Level 10



This is really useful. For what it's worth we handle this slightly differently in our Data Adapter, by checking input validity up front using SAS code, and if something's not right, writing a similar JSON message and issuing an ENDSAS statement to quit the rest of the program execution. Where an error occurs we handle the output at the frontend and keep the logs in an array, rather than suppressing the SAS log.


This is really useful for making SAS/ACCESS STPs more fault tolerant though. Thanks again.





SAS is headed back to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team.

Interested in speaking? Content from our attendees is one of the reasons that makes SAS Innovate such a special event!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 3 in conversation