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.
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!
data work.binarybase;
format bin $hex500. z $hex.;
do x=1 to 250;
z=byte(x);
bin=trim(bin)!!z;
output;
end;
run;
%mp_ds2cards(base_ds=work.binarybase
, showlog=YES
, cards_file="%sysfunc(pathname(work))/c2.sas"
, tgt_ds=work.binarycompare
, append=
)
%inc "%sysfunc(pathname(work))/c2.sas"/source2 lrecl=32767;
proc compare base=work.binarybase compare=work.binarycompare;
run;
%mp_assert(
iftrue=(&sysinfo=0),
desc=work.binarybase dataset is identical,
outds=work.test_results
)
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/.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.