PING
0.9
Statistical data handling and processing in production environment
|
Check for errors and set status code and messages
i_errcode
: error code unique to the calling macro;i_cond
: condition - logical expression, will be evaluated and returned by the macro; when evaluated as true, status is set to error;mac
: (option) name of macro where error condition occured; default: not used;txt
: (option) error message, further information will be issued to the SAS log; default: no customised error message displayed;verb
: (option) verbose mode - parameter (yes/no/err/warn
) used to issue message to the SAS log even if i_cond
evaluates to false (yes
), in case of error only (err
) or none (no
); default is err
.err
: evaluated condition i_cond
, either:
cond
is true),cond
is false).If the condition i_cond
is true, a message is being issued to the SAS log and the following macro variables are assigned:
G_PING_ERROR_MACRO
(calling macro program where the error occurred) <- value of mac
or UNKNOWN
,G_PING_ERROR_CODE
(error code) <- value of i_errcode
,G_PING_ERROR_MSG
<- value of txt
(error message) or empty,otherwise these macro variables are reset. They should be defined as global
elsewhere (e.g., when setting default environment variables).
The calling program should determine the name of the macro program currently running with the following line of code at the top of the program:
Do not use &sysmacroname
as the value of macro parameter G_PING_ERROR_MACRO
directly, because it will have a value of error_handle
(i.e., name of this macro).
If verb
has value yes
, a message is being written to the SAS log even when i_errcode
is not a true condition.
returns res=1
and displays the following error message:
while evaluating the same condition on a different variable:
returns res=0
and displays (because of the verbose mode) the following OK
message:
Run macro %_example_error_handle
for more examples.
This program is adapted from the macro _handleError
distributed in SASUnit
framework (the Unit testing framework for SAS programs, under GPL license...) into SPRING framework. For further information, refer to https://sourceforge.net/p/sasunit/wiki/User%27s%20Guide/
Wilson, S.A. (2011): "The validator: A macro to validate parameters".