Macros for SAS Application Developers
https://github.com/sasjs/core
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:$4|TEST_COMMENTS:$256|
24  |---|---|---|
25  |User Provided description|PASS|Dataset &inds contained ALL columns|
26 
27  @version 9.2
28  @author Allan Bowe
29 
30 **/
31 
32 %macro mp_assert(iftrue=(1=1),
33  desc=0,
34  outds=work.test_results
35 )/*/STORE SOURCE*/;
36 
37  data ;
38  length test_description $256 test_result $4 test_comments $256;
39  test_description=symget('desc');
40  test_comments="&sysmacroname: Test result of "!!symget('iftrue');
41  %if %eval(%unquote(&iftrue)) %then %do;
42  test_result='PASS';
43  %end;
44  %else %do;
45  test_result='FAIL';
46  %end;
47  run;
48 
49  %local ds ;
50  %let ds=&syslast;
51  proc append base=&outds data=&ds;
52  run;
53  proc sql;
54  drop table &ds;
55 
56 %mend mp_assert;