@atesera wrote:
ok thanks for that. Yeah, I would like the program to stop even for those errors because sometimes I create those man-made errors to stop the program going further as it will mess up the rest of the datasets.
You might want to use something like this macro that Tom Hoffman created almost 30 years ago.
(You can replace the calls to his %OPTVAL() macros with calls to %SYSFUNC(GETOPTION()) instead.)
%macro bailout
/*----------------------------------------------------------------------
Stop processing a batch job when specified condition is true AND option
ERRORABEND is turned on. Pop up window in interactive environment.
----------------------------------------------------------------------*/
(cond /* SAS statement which evaluates to 0 or 1 */
,code=13 /* Abend code */
,msg1= /* Message 1 */
,msg2= /* Message 2 */
,msg3= /* Message 3 */
,msg4= /* Message 4 */
,msg5= /* Message 5 */
,env=&sysmenv /* used to fix version 8 bug */
);
/*----------------------------------------------------------------------
This code was developed by HOFFMAN CONSULTING as part of a FREEWARE
macro tool set.
-----------------------------------------------------------------------
Usage:
%macro test;
%local macro parmerr;
%let macro = TEST;
%parmv(INTERVAL,_req=1,_words=1)
%parmv(IVAR,_req=1)
%if (%length(&visit) > 7) %then
%parmv(IVAR,_msg=SAS name containing 7 or less characters)
;
%parmv(LZERO,_req=1)
%parmv(UZERO,_req=1)
%parmv(HIGH,_req=1,_val=0 1)
%parmv(DAY,_req=1)
%parmv(PRINT,_req=1,_val=0 1)
%if (&parmerr) %then %goto quit;
... SAS program ...
%quit:
%bailout(&parmerr)
%mend test;
------------------------------------------------------------------------
Notes:
No action is taken when COND=0.
Messages are always written to the log.
When in DMS (but not on the command line), a window with messages will
be displayed. Message line length maximum is 65 characters.
When ERRORABEND is turned on, the job is aborted.
Note that the BAILOUT macro is typically invoked once at the end of a
report macro. It is not invoked by utility macros that are intended for
use by a report macro. The macro tool programmer must not localize
PARMERR so that it is passed to the calling macro.
-----------------------------------------------------------------------
History:
09OCT96 TRHoffman Creation
22FEB99 TRHoffman Add message window for interactive environment,
as suggested by Paulette Staum.
11APR00 TRHoffman Suppressd macro window when invoked from command line.
02JUN00 TRHoffman Always write messages to log.
12OCT01 TRHoffman Added ENV parameter to avoid version 8 bug when
called indirectly from command line via gsub.
(tracking number us5532399).
----------------------------------------------------------------------*/
%local j;
%*----------------------------------------------------------------------
Do nothing when calling macro contains no errors.
-----------------------------------------------------------------------;
%if (%eval(&cond)=0) %then %goto quit;
%*----------------------------------------------------------------------
When not in DMS (either SAS/CONNECT or batch), write messages to log.
When no messages specify, create a default one.
Abort if ERRORABEND is on.
-----------------------------------------------------------------------;
%if (%optval(dms) = NODMS) %then %do;
%if ^%length(&msg1&msg2) %then
%let msg1=Submitted code contains errors. See the LOG for details.;
run;
data _null_;
put
/ "&msg1 "
/ "&msg2 "
/ "&msg3 "
/ "&msg4 "
/ "&msg5 "
/ ' '
;
%if (%optval(ERRORABEND) = ERRORABEND) %then %do;
abort return &code;
%end;
run;
%end;
%*----------------------------------------------------------------------
Always write messages to log.
-----------------------------------------------------------------------;
%else %do;
%do j = 1 %to 5;
%if %length(&&msg&j) %then %put %quote(&&msg&j);
%end;
%*----------------------------------------------------------------------
In DMS mode, pop up a window, except when on the command line.
When no messages specified, create a default one.
-----------------------------------------------------------------------;
%if (&env = S) %then %do;
%if ^%length(&msg1&msg2) %then
%let msg1=Submitted code contains errors. See the LOG for details.;
%window ERRORS columns=65 rows=12 icolumn=5 irow=10
#1 "&msg1 "
#2 "&msg2 "
#3 "&msg3 "
#4 "&msg4 "
#5 "&msg5 "
#7 "Press ENTER to close this window."
;
%display errors bell delete;
%end;
%*----------------------------------------------------------------------
Switch to log window if on comand line.
-----------------------------------------------------------------------;
%else %if (&sysmenv = D) %then %do;
log
%end;
%end; %* DMS;
%quit:
%mend bailout;
... View more