From: Raj on
Hi,
Is there a way to know in the program if a previous data step or proc
step executed correctly or not?

From: Martin Gregory on
On 02/13/2007 07:13 PM, Raj wrote:
> Hi,
> Is there a way to know in the program if a previous data step or proc
> step executed correctly or not? I mean not by looking at the log but
> programatically !!
>
> thanks,
> Raj
>

Hi Raj,

you need to enclose your code in a macro and check the result of the
automatic macro variable SYSERR. Check the docs for the values. Since
there is no way (that I know of), to exit a macro, this is one of those
cases where %GOTO is useful. Here's an outline of how to use it and to
pass back information about what happened. The only way to do this is
via a global macro var, so give the caller the chance to name it:

%macro x (rc=rcx) ;

%global &rc ;
/* set a default failure code in case something unexpected happens */
%let &rc=99 ;

data step code ... ;

%if &syserr > 4 %then %do ;
/* set your return code - a global macro var */
%let &rc=1 ;
/* assuming you want to exit the macro on error */
%goto DONE ;
%end ;

next step ;
...
%if &syserr > 4 %then %do ;
/* set your return code - a global macro var */
%let &rc=2 ;
/* assuming you want to exit the macro on error */
%goto DONE ;
%end ;

/* should only execute if successful */
%let &rc=0 ;
%DONE:
%mend ;

regards,

Martin