All data used for testing is defined directly in the script via `datalines4` blocks within `DATA STEP`.
1 Code Block
DATA STEP Data
Explanation : This `DATA STEP` block creates the `test1` dataset. It reads character strings from `datalines4`, assigns them to the `libds` variable, then calls the `%mp_validatecol` macro with type `LIBDS` to validate if `libds` is a valid SAS library/dataset name. Only observations where `is_libds` is 1 (valid) are kept, filtering out non-conforming entries.
Copied!
data test1;
infile datalines4 dsd;
input;
libds=_infile_;
%mp_validatecol(libds,LIBDS,is_libds)
if is_libds=1;
datalines4;
some.libname
!lib.blah
%abort
definite.ok
not.ok!
nineletrs._
;;;;
run;
1
DATA test1;
2
INFILE datalines4 dsd;
3
INPUT;
4
libds=_infile_;
5
%mp_validatecol(libds,LIBDS,is_libds)
6
IF is_libds=1;
7
datalines4;
8
some.LIBNAME
9
!lib.blah
10
%abort
11
definite.ok
12
not.ok!
13
nineletrs._
14
;;;;
15
RUN;
2 Code Block
Macro (%mp_assertdsobs)
Explanation : This macro call uses `%mp_assertdsobs` to verify that the `work.test1` dataset contains exactly 2 observations after `LIBDS` validation, confirming the expected behavior. The result of this assertion is stored in the `work.test_results` dataset.
Explanation : This `DATA STEP` creates `test2` by reading strings from `datalines4` into `infile`. The `%mp_validatecol` macro is then called with type `ISNUM` to determine if each string represents a valid number. Only valid numeric observations (`is_numeric=1`) are kept in the `test2` dataset.
Copied!
data test2;
infile datalines4 dsd;
input;
infile=_infile_;
%mp_validatecol(infile,ISNUM,is_numeric)
if is_numeric=1;
datalines4;
1
0001
1e6
-44
above are good
the rest are bad
%abort
1&somethingverybad.
&
+-1
;;;;
run;
1
DATA test2;
2
INFILE datalines4 dsd;
3
INPUT;
4
INFILE=_infile_;
5
%mp_validatecol(INFILE,ISNUM,is_numeric)
6
IF is_numeric=1;
7
datalines4;
8
1
9
0001
10
1e6
11
-44
12
above are good
13
the rest are bad
14
%abort
15
1&somethingverybad.
16
&
17
+-1
18
;;;;
19
RUN;
4 Code Block
Macro (%mp_assertdsobs)
Explanation : This `%mp_assertdsobs` macro call verifies that the `work.test2` dataset contains exactly 4 observations after `ISNUM` validation, confirming the correct recognition of numeric values by `mp_validatecol`. The result is added to `work.test_results`.
Explanation : This `DATA STEP` creates `test3`. It reads strings from `datalines4` into `infile` and uses `%mp_validatecol` with type `FORMAT` to identify strings that are valid SAS format names. Only observations with valid formats (`is_format=1`) are kept.
Copied!
data test3;
infile datalines4 dsd;
input;
infile=_infile_;
%mp_validatecol(infile,FORMAT,is_format)
if is_format=1;
datalines4;
$.
$format.
$format12.2
somenum.
somenum12.4
above are good
the rest are bad
%abort
1&somethingverybad.
&
+-1
.
a.A
$format12.1b
$format12.1b1
;;;;
run;
1
DATA test3;
2
INFILE datalines4 dsd;
3
INPUT;
4
INFILE=_infile_;
5
%mp_validatecol(INFILE,FORMAT,is_format)
6
IF is_format=1;
7
datalines4;
8
$.
9
$FORMAT.
10
$format12.2
11
somenum.
12
somenum12.4
13
above are good
14
the rest are bad
15
%abort
16
1&somethingverybad.
17
&
18
+-1
19
.
20
a.A
21
$format12.1b
22
$format12.1b1
23
;;;;
24
RUN;
6 Code Block
Macro (%mp_assertdsobs)
Explanation : This `%mp_assertdsobs` macro call validates that `work.test3` contains 5 observations, confirming that the `mp_validatecol` macro correctly identifies valid SAS formats. The result is added to `work.test_results`.
Explanation : This `DATA STEP` creates `test4`, reads strings from `datalines4` into `infile`, and uses `%mp_validatecol` with type `ISINT` to check if each string represents a valid integer. Only observations that are integers (`is_integer=1`) are kept.
Copied!
data test4;
infile datalines4 dsd;
input;
infile=_infile_;
%mp_validatecol(infile,ISINT,is_integer)
if is_integer=1;
datalines4;
1
1234
-134
-1.0
1.0
0
above are good
the rest are bad
0.1
1.1
-0.001
%abort
1&somethingverybad.
&
+-1
.
a.A
$format12.1b
$format12.1b1
;;;;
run;
1
DATA test4;
2
INFILE datalines4 dsd;
3
INPUT;
4
INFILE=_infile_;
5
%mp_validatecol(INFILE,ISINT,is_integer)
6
IF is_integer=1;
7
datalines4;
8
1
9
1234
10
-134
11
-1.0
12
1.0
13
0
14
above are good
15
the rest are bad
16
0.1
17
1.1
18
-0.001
19
%abort
20
1&somethingverybad.
21
&
22
+-1
23
.
24
a.A
25
$format12.1b
26
$format12.1b1
27
;;;;
28
RUN;
8 Code Block
Macro (%mp_assertdsobs)
Explanation : This final `%mp_assertdsobs` call ensures that the `work.test4` dataset contains 6 observations, proving that `mp_validatecol` correctly identifies integer values. The result is stored in `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 testing framework for SAS(R) programs. For copyright information and terms of usage under the GNU Lesser General Public License see included file README.md 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.