Published on :
Test INTERNAL_CREATION

Unit tests for the mp_makedata macro

This code is also available in: Deutsch Español Français
Awaiting validation
This program executes a series of unit tests to ensure that the `%mp_makedata` macro functions correctly. It creates tables with specific constraints (primary keys, non-null values) via `PROC SQL`, populates these tables using the macro, then uses `%mp_assert` and `DATA _NULL_` steps to check the number of observations, data integrity (string length), and error handling.
Data Analysis

Type : INTERNAL_CREATION


Data is dynamically generated by the `%mp_makedata` macro based on the structure of the tables defined in the script (work.example, work.example2).

1 Code Block
PROC SQL Data
Explanation :
Definition of the test table `work.example` structure with integrity constraints, followed by the generation of 500 test observations via `%mp_makedata`.
Copied!
1PROC SQL;
2create TABLE work.example(
3 TX_FROM float FORMAT=datetime19.,
4 DD_TYPE char(16),
5 DD_SOURCE char(2048),
6 DD_SHORTDESC char(256),
7 constraint pk primary key(tx_from, dd_type,dd_source),
8 constraint nnn not null(DD_SHORTDESC)
9);
10%mp_makedata(work.example,obs=500)
2 Code Block
MACRO CALL
Explanation :
Verification via `%mp_assert` that the number of observations in the created table is exactly 500, using the utility macro `%mf_nobs`.
Copied!
1%mp_assert(
2 iftrue=("%mf_nobs(work.example)"="500"),
3 desc=Check that 500 rows were created,
4 outds=work.test_results
5)
3 Code Block
DATA STEP
Explanation :
Technical Data Step to retrieve the length of the `dd_source` variable from the first observation and store it in the macro variable `lenvar` for later assertion.
Copied!
1DATA _null_;
2 SET work.example;
3 call symputx('lenvar',LENGTH(dd_source));
4 stop;
5RUN;
4 Code Block
MACRO CALL
Explanation :
Assertion checking that the `dd_source` variable has been populated to its full declared length (2048 characters).
Copied!
1%mp_assert(
2 iftrue=("&lenvar"="2048"),
3 desc=Check that entire LENGTH of variable is populated,
4 outds=work.test_results
5)
5 Code Block
PROC SQL Data
Explanation :
Creation of a second table `work.example2` without primary key constraints to test the default behavior of data generation.
Copied!
1PROC SQL;
2create TABLE work.example2(
3 TX_FROM float FORMAT=datetime19.,
4 DD_TYPE char(16),
5 DD_SOURCE char(2048),
6 DD_SHORTDESC char(256),
7 some_num num
8);
9%mp_makedata(work.example2)
6 Code Block
MACRO CALL
Explanation :
Final verification that the execution proceeded without system errors (`&syscc=0`) for the table without keys.
Copied!
1%mp_assert(
2 iftrue=(&syscc=0),
3 desc=Ensure tables without keys still generate,
4 outds=work.test_results
5)
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.