Published on :
Unit test CREATION_INTERNE

Unit test for the MCF_LENGTH macro

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins with an initial initialization of the `%mcf_length` macro with specific options (`wrap=YES`, `insert_cmplib=YES`). A `DATA STEP` is then used to call `%mcf_length` with a range of input values (standard and special missing values, integers of various magnitudes) and stores the results in dedicated macro variables via the `call symputx` function. These macro variables are subsequently used in a series of calls to the `%mp_assert` macro, which acts as a unit testing mechanism, to confirm that the lengths calculated by `%mcf_length` conform to expectations. The script also includes checks of the `&syscc` system macro variable before and after a second initialization of `%mcf_length`, to ensure system integrity and the absence of compilation or execution errors.
Data Analysis

Type : CREATION_INTERNE


The script does not rely on external SAS datasets or the SASHELP system. It operates only on numeric literals directly defined in the code and the results of SAS macros, which are then stored in internal macro variables. A temporary 'test' dataset is created by the `DATA STEP` but is primarily used for the `call symputx` call and does not contain persistent data.

1 Code Block
Macro Call (%mcf_length)
Explanation :
This block performs the first initialization or recompilation of the `%mcf_length` macro. The parameters `wrap=YES` and `insert_cmplib=YES` are specific configuration options for this macro, probably related to macro library management or the integration of generated code.
Copied!
1%mcf_length(wrap=YES, insert_cmplib=YES)
2 Code Block
DATA STEP Data
Explanation :
This `DATA STEP` is designed to test the `%mcf_length` macro with various inputs. For each test, the `mcf_length()` function is called with a numeric or missing value, and the result is stored in a macro variable (e.g., `&null`, `&special`, etc.) using `call symputx`. The `test` dataset created is an artifact of the `DATA STEP` but its content is not used directly for validation.
Copied!
1DATA test;
2 call symputx('null',mcf_length(.));
3 call symputx('special',mcf_length(._));
4 call symputx('three',mcf_length(1));
5 call symputx('four',mcf_length(10000000));
6 call symputx('five',mcf_length(12345678));
7 call symputx('six',mcf_length(1234567890));
8 call symputx('seven',mcf_length(12345678901234));
9 call symputx('eight',mcf_length(12345678901234567));
10RUN;
3 Code Block
Macro Calls (%mp_assert)
Explanation :
This block contains a series of calls to the `%mp_assert` macro to perform assertions on the results of `%mcf_length` and the system state. Each `%mp_assert` evaluates a condition (`iftrue`) and provides a test description (`desc`). These tests verify that the calculated lengths are correct for different scenarios, including missing values and numbers of different lengths, as well as the state of the `&syscc` system macro variable.
Copied!
1%mp_assert(
2 iftrue=(%str(&null)=%str(0)),
3 desc=Check IF NULL returns 0
4)
5%mp_assert(
6 iftrue=(%str(&special)=%str(3)),
7 desc=Check IF special missing ._ returns 3
8)
9%mp_assert(
10 iftrue=(%str(&three)=%str(3)),
11 desc=Check for LENGTH 3
12)
13%mp_assert(
14 iftrue=(%str(&four)=%str(4)),
15 desc=Check for LENGTH 4
16)
17%mp_assert(
18 iftrue=(%str(&five)=%str(5)),
19 desc=Check for LENGTH 5
20)
21%mp_assert(
22 iftrue=(%str(&six)=%str(6)),
23 desc=Check for LENGTH 6
24)
25%mp_assert(
26 iftrue=(%str(&seven)=%str(3)),
27 desc=Check for LENGTH 3
28)
29%mp_assert(
30 iftrue=(%str(&eight)=%str(8)),
31 desc=Check for LENGTH 8
32)
33%mp_assert(
34 iftrue=(&syscc=0),
35 desc=Check syscc=0 before re-initialisation
36)
4 Code Block
Macro Call (%mcf_length)
Explanation :
This second call to `%mcf_length` serves to test the macro's behavior in case of recompilation or multiple initializations. It is often used in unit tests to ensure that the macro can be called multiple times without undesirable side effects.
Copied!
1%mcf_length(wrap=YES, insert_cmplib=YES)
5 Code Block
Macro Call (%mp_assert)
Explanation :
This final call to `%mp_assert` verifies that the `&syscc` system macro variable is still 0 after the second initialization of `%mcf_length`. This confirms that recompiling or calling the macro a second time has not introduced any major system errors.
Copied!
1%mp_assert(
2 iftrue=(&syscc=0),
3 desc=Check syscc=0 after re-initialisation
4)
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.