Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_assert.test.1.sas
Go to the documentation of this file.
1/**
2
3 @file
4 @brief Testing mp_assert macro
5 @details The results dataset is shared. Packages built on these assertion
6 macros append their own statuses to work.test_results, and a status can be
7 longer than PASS or FAIL - CHECK, for example, is used to flag an item for
8 review. When such a package appends to a results dataset created with a
9 shorter column, PROC APPEND refuses the rows outright:
10
11 WARNING: Variable test_result has different lengths on BASE and DATA files
12 ERROR: No appending done because of anomalies listed above.
13
14 so the column must be wide enough for the longer status.
15
16 <h4> SAS Macros </h4>
17 @li mp_assert.sas
18
19 @sasjslint {"noBannedStrings": false}
20**/
21
22/* create the results dataset with the assertion macros, as any test does */
23%mp_assert(
24 iftrue=(1=1),
25 desc=Checking result was created,
26 outds=work.test_results
27)
28
29/* a downstream package appends its own 5 character status */
30data work.append_test;
31 length test_result $5 test_description $256 test_comments $256;
32 test_result='CHECK';
33 test_description='Checking a 5 character status survives the append';
34 test_comments='Simulates a downstream package appending to the results';
35run;
36
37proc append base=work.test_results data=work.append_test;
38run;
39
40/* a refused append leaves the session in syntax check mode (OBS=0), which
41 would silently skip the assertions below - reset it so the problem is
42 reported instead of hidden */
43options obs=max;
44
45%let checkval=;
46%let checklen=0;
47data _null_;
48 set work.test_results;
49 if test_result='CHECK' then do;
50 call symputx('checkval',test_result);
51 call symputx('checklen',lengthc(test_result));
52 end;
53run;
54
55%mp_assert(
56 iftrue=("&checkval"="CHECK"),
57 desc=Checking a 5 character status is not refused by the append
58)
59
60%mp_assert(
61 iftrue=(&checklen=5),
62 desc=Checking the results column holds a 5 character status
63)