Published on :
Macro EXTERNAL

Assertion of a Non-Empty Dataset

This code is also available in: Deutsch Español Français
This macro, `assert_not_empty`, serves as an assertion routine. It first checks for the existence of the dataset passed via the `DS` parameter. If the dataset does not exist, or if it exists but contains no observations, an event is triggered by calling an external macro `%generate_event`. The details of this event (message, level, type, etc.) can be customized via parameters. If no custom message is provided, a default message is automatically generated to indicate the nature of the problem (non-existent or empty).
Data Analysis

Type : EXTERNAL


The macro is designed to operate on a dataset whose name is provided via the `DS` parameter, which is therefore external to the macro itself. Its operation also depends on the `%generate_event` macro, which is not defined in this script and must be available in the SAS environment.

1 Code Block
Macro
Explanation :
This block defines the `assert_not_empty` macro. It uses the macro functions `%exist` to check if the dataset exists and `%obs` to count its observations. If the dataset is non-existent or empty, a local variable `EVENT_COUNT` is set to 1. In this case, the external macro `%generate_event` is called to signal the anomaly, passing the corresponding parameters to it. The global variable `futs_tst_cnt` is incremented, suggesting that this macro is part of a larger testing framework.
Copied!
1%macro assert_not_empty( DS,
2 MESSAGE=,
3 TYPE=,
4 LEVEL=,
5 ATTACHDATA=,
6 ATTACHFILE=,
7 METRIC=,
8 PROPERTIES=,
9 ON_EVENT=,
10 DESCRIPTION=, ABORT= );
11 
12%local EVENT_COUNT DS_EXIST;
13%let EVENT_COUNT = 0;
14%let DS_EXIST = %exist(&DS);
15%*put LOG: ds_exist = <&DS_EXIST.>;
16 
17%IF &DS_EXIST eq 0 %THEN %DO;
18 %let EVENT_COUNT = 1;
19 %IF &MESSAGE = %str() %THEN %let MESSAGE = DATA SET &DS does not exist;
20%END;
21%ELSE %DO;
22 %IF %obs(&DS) eq 0 %THEN %DO;
23 %let EVENT_COUNT = 1;
24 %IF &MESSAGE = %str() %THEN
25 %let MESSAGE = DATA SET &DS is empty;
26 %END;
27%END;
28 
29%let futs_tst_cnt = %eval(&futs_tst_cnt.+1);
30 
31%IF &EVENT_COUNT gt 0 %THEN
32 %generate_event(TYPE=&TYPE, LEVEL=&LEVEL,
33 MESSAGE=&MESSAGE,
34 ATTACHDATA=&ATTACHDATA, ATTACHFILE=&ATTACHFILE,
35 METRIC=&METRIC,
36 PROPERTIES=&PROPERTIES,
37 ON_EVENT=&ON_EVENT,
38 DESCRIPTION=&DESCRIPTION, ABORT=&ABORT);
39 
40%mend assert_not_empty;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright (c) 2015 John Jacobs. All rights reserved.