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**/
20
21/* create the results dataset with the assertion macros, as any test does */
22%mp_assert(
23 iftrue=(1=1),
24 desc=Checking result was created,
25 outds=work.test_results
26)
27
28/* a downstream package appends its own 5 character status */
29data work.append_test;
30 length test_result $5 test_description $256 test_comments $256;
31 test_result='CHECK';
32 test_description='Checking a 5 character status survives the append';
33 test_comments='Simulates a downstream package appending to the results';
34run;
35
36proc append base=work.test_results data=work.append_test;
37run;
38
39/* a refused append leaves the session in syntax check mode (OBS=0), which
40 would silently skip the assertions below - reset it so the problem is
41 reported instead of hidden */
42options obs=max;
43
44%let checkval=;
45%let checklen=0;
46data _null_;
47 set work.test_results;
48 if test_result='CHECK' then do;
49 call symputx('checkval',test_result);
50 call symputx('checklen',lengthc(test_result));
51 end;
52run;
53
54%mp_assert(
55 iftrue=("&checkval"="CHECK"),
56 desc=Checking a 5 character status is not refused by the append
57)
58
59%mp_assert(
60 iftrue=(&checklen=5),
61 desc=Checking the results column holds a 5 character status
62)