Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_distinctfmtvalues.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_distinctfmtvalues macro
4
5 <h4> SAS Macros </h4>
6 @li mp_distinctfmtvalues.sas
7 @li mp_assert.sas
8 @li mp_assertmodel.sas
9
10**/
11
12data work.fmtvals;
13 dt='01jan2020'd; output;
14 dt='01jan2020'd; output;
15 dt='02feb2021'd; output;
16 dt='03mar2022'd; output;
17 format dt date9.;
18run;
19
20%mp_distinctfmtvalues(libds=work.fmtvals,var=dt,outds=work.dfv_out)
21
22data work.dfv_model;
23 length formatted_value $2000;
24 stop;
25run;
26
27%mp_assertmodel(work.dfv_out,
28 base=work.dfv_model,
29 key=formatted_value,
30 desc=Checking formatted value model and key,
31 outds=work.test_results
32)
33
34proc sql noprint;
35 select count(*) into: n_vals from work.dfv_out;
36 select count(*) into: n_hit from work.dfv_out
37 where formatted_value='01JAN2020';
38 select count(*) into: n_expected from work.dfv_out
39 where formatted_value in ('01JAN2020','02FEB2021','03MAR2022');
40quit;
41
42%mp_assert(
43 iftrue=(&n_vals=3),
44 desc=Checking that duplicate formatted values collapse to one row,
45 outds=work.test_results
46)
47
48%mp_assert(
49 iftrue=(&n_hit=1),
50 desc=Checking that the value carries the variable format,
51 outds=work.test_results
52)
53
54%mp_assert(
55 iftrue=(&n_expected=3),
56 desc=Checking all three formatted dates are present,
57 outds=work.test_results
58)