Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_assert.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Generic assertion
4 @details Useful in the context of writing sasjs tests. The results of the
5 test are _appended_ to the &outds. table.
6
7 Example usage:
8
9 %mp_assert(iftrue=(1=1),
10 desc=Obviously true
11 )
12
13 %mp_assert(iftrue=(1=0),
14 desc=Will fail
15 )
16
17 @param [in] iftrue= (1=1) A condition where, if true, the test is a PASS.
18 Else, the test is a fail.
19
20 @param [in] desc= (Testing observations) The user provided test description
21 @param [out] outds= (work.test_results) The output dataset to contain the
22 results. If it does not exist, it will be created, with the following format:
23 |TEST_DESCRIPTION:$256|TEST_RESULT:$5|TEST_COMMENTS:$256|
24 |---|---|---|
25 |User Provided description|PASS|Dataset &inds contained ALL columns|
26
27 <h4> SAS Macros </h4>
28 @li mf_getuniquename.sas
29 @li mddl_assert.sas
30
31 @version 9.2
32 @author Allan Bowe
33
34**/
35
36%macro mp_assert(iftrue=(1=1),
37 desc=0,
38 outds=work.test_results
39)/*/STORE SOURCE*/;
40
41 %local ds;
42 %let ds=work.%mf_getuniquename(prefix=mp_assert);
43 %mddl_assert(&ds)
44 data &ds;
45 if 0 then set &ds;
46 test_description=symget('desc');
47 test_comments="&sysmacroname: Test result of "!!symget('iftrue');
48 %if %eval(%unquote(&iftrue)) %then %do;
49 test_result='PASS';
50 %end;
51 %else %do;
52 test_result='FAIL';
53 %end;
54 run;
55
56 proc append base=&outds data=&ds;
57 run;
58 proc sql;
59 drop table &ds;
60 quit;
61
62%mend mp_assert;