Published on :
Macro CREATION_INTERNE

Test of the mf_getvarcount macro

This code is also available in: Deutsch Español Français
Awaiting validation
This program generates local test data containing a mix of numeric and character variables. It then executes a series of assertions (via the %mp_assert macro) to validate that the %mf_getvarcount macro correctly counts variables, globally and by type (numeric or character filter).
Data Analysis

Type : CREATION_INTERNE


The test tables (work.all, work.nums, work.chars) are generated by a Data Step at the beginning of the script.

1 Code Block
DATA STEP Data
Explanation :
Creation of test tables in the WORK library with defined variable structures (mixed, numeric only, character only).
Copied!
1DATA work.all work.nums(keep=num1 num2) work.chars(keep=char1 char2);
2 LENGTH num1 num2 8 char1 char2 char3 $4;
3 call missing (of _all_);
4 OUTPUT;
5RUN;
2 Code Block
MACRO
Explanation :
Sequence of unit tests. Uses %mp_assertscope to check the cleanliness of the macro environment, and %mp_assert to validate the returns of the %mf_getvarcount function according to different filtering criteria.
Copied!
1%mp_assertscope(SNAPSHOT)
2%put scope check:%mf_getvarcount(work.all);
3%mp_assertscope(COMPARE)
4 
5%mp_assert(
6 iftrue=(%mf_getvarcount(work.all)=5),
7 desc=%str(Checking for mixed vars),
8 outds=work.test_results
9)
10 
11%mp_assert(
12 iftrue=(%mf_getvarcount(work.all,typefilter=C)=3),
13 desc=%str(Checking for char in mixed vars),
14 outds=work.test_results
15)
16/* ... suite des assertions ... */
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.