BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DominicPazzulaF
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;
	%end;
run;
%mend;

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;
MPRINT(STATUS_OUTPUT):   run;

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?

1 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4
DominicPazzulaF
Fluorite | Level 6

Added 

	option NOSYNTAXCHECK ;

Which solved the problem.

Quentin
Super User

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;
%end;
DominicPazzulaF
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.

boemskats
Lapis Lazuli | Level 10

Hi, 

 

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.

 

Nik 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2794 views
  • 8 likes
  • 3 in conversation