Published on :
Macro MIXTE

Test of the mp_ds2cards and mp_assert macros

This code is also available in: Deutsch Español Français
Awaiting validation
The script implements two distinct test scenarios. The first scenario uses the `sashelp.cars` dataset to illustrate conversion to `CARDS` format and dataset recreation, followed by a data integrity check using `PROC COMPARE`. The second scenario, meanwhile, internally creates a binary dataset and applies the same conversion, recreation, and comparison process, ensuring the accuracy of binary data. Each test is completed with an assertion using the `mp_assert` macro to formally validate the results of the dataset comparisons.
Data Analysis

Type : MIXTE


The script leverages the built-in `sashelp.cars` dataset and internally generates a `work.binarybase` dataset via a DATA step. There is no dependency on external data not managed by the script or not originating from standard SAS libraries.

1 Code Block
Macro mp_ds2cards and PROC COMPARE
Explanation :
This block illustrates the conversion of the `sashelp.cars` dataset into a temporary `CARDS` file (`cars.sas`) using the `mp_ds2cards` macro. The dataset is then recreated as `work.test` via an `%inc` statement. A `PROC COMPARE` is used to check the identity of the original and recreated datasets, and the `mp_assert` macro validates the result of this comparison.
Copied!
1%mp_ds2cards(base_ds=sashelp.cars
2 , tgt_ds=work.test
3 , cards_file= "%sysfunc(pathname(work))/cars.sas"
4 , showlog=NO
5)
6%inc "%sysfunc(pathname(work))/cars.sas"/source2 lrecl=32767;
7 
8PROC COMPARE base=sashelp.cars compare=work.test;
9QUIT;
10 
11%mp_assert(
12 iftrue=(&sysinfo=1),
13 desc=sashelp.cars is identical except for ds label,
14 outds=work.test_results
15)
2 Code Block
DATA STEP, Macro mp_ds2cards and PROC COMPARE Data
Explanation :
This block begins with the creation of a `work.binarybase` dataset containing a sequence of binary data. The `mp_ds2cards` macro is then called to convert `work.binarybase` into a `CARDS` file (`c2.sas`), which is then used to recreate the dataset as `work.binarycompare`. Finally, `PROC COMPARE` checks the perfect identity between the original dataset and its recreated version, with `mp_assert` confirming the absence of differences (return code `SYSINFO=0`).
Copied!
1DATA work.binarybase;
2 FORMAT bin $hex500. z $hex.;
3 DO x=1 to 250;
4 z=byte(x);
5 bin=trim(bin)!!z;
6 OUTPUT;
7 END;
8RUN;
9 
10%mp_ds2cards(base_ds=work.binarybase
11 , showlog=YES
12 , cards_file="%sysfunc(pathname(work))/c2.sas"
13 , tgt_ds=work.binarycompare
14 , append=
15)
16 
17%inc "%sysfunc(pathname(work))/c2.sas"/source2 lrecl=32767;
18 
19PROC COMPARE base=work.binarybase compare=work.binarycompare;
20RUN;
21 
22%mp_assert(
23 iftrue=(&sysinfo=0),
24 desc=work.binarybase dataset is identical,
25 outds=work.test_results
26)
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 2010-2023 HMS Analytical Software GmbH, http://www.analytical-software.de This file is part of SASUnit, the unit test framework for SAS(R) programs. For copyright information and terms of use under the GNU Lesser General Public License, see the included README.md file or https://github.com/HMS-Analytical-Software/SASUnit/wiki/readme/.