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;
BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
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 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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