Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_recursivejoin.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_recursivejoin macro
4
5 <h4> SAS Macros </h4>
6 @li mp_recursivejoin.sas
7 @li mp_assert.sas
8 @li mp_assertmodel.sas
9 @li mp_assertscope.sas
10
11**/
12
13%let recursive_saved_obs=%sysfunc(getoption(obs,keyword));
14%let recursive_saved_firstobs=%sysfunc(getoption(firstobs,keyword));
15options obs=max firstobs=1;
16
17data work.have;
18 p=1;c=2;output;
19 p=2;c=3;output;
20 p=2;c=4;output;
21 p=3;c=5;output;
22 p=6;c=7;output;
23 p=8;c=9;output;
24run;
25
26%mp_assertscope(SNAPSHOT)
27%mp_recursivejoin(base_ds=work.have,outds=work.want,matchval=1
28 ,parentvar=p,childvar=c)
29%mp_assertscope(COMPARE,
30 desc=Checking mp_recursivejoin recursive call does not leak scope,
31 outds=work.test_results
32)
33
34data work.join_model;
35 length level p c 8;
36 call missing(level,p,c);
37 stop;
38run;
39
40%mp_assertmodel(work.want,base=work.join_model,
41 desc=Checking mp_recursivejoin output model,
42 outds=work.test_results
43)
44
45proc sql noprint;
46 select count(*) into: n_pairs from work.want
47 where (p=1 and c=2) or (p=2 and c=3) or (p=2 and c=4) or (p=3 and c=5);
48 select count(*) into: n_deep from work.want where c=5;
49 select count(*),
50 coalesce(sum(level=0 and p=1 and c=2),0),
51 coalesce(sum(level=1 and p=2 and c=3),0),
52 coalesce(sum(level=1 and p=2 and c=4),0),
53 coalesce(sum(level=2 and p=3 and c=5),0),
54 coalesce(sum(level=2 and p=4 and c=.),0),
55 coalesce(sum(level=3 and p=5 and c=.),0)
56 into :n_total, :n_root, :n_23, :n_24, :n_35, :n_leaf4, :n_leaf5
57 from work.want;
58quit;
59
60%mp_assert(
61 iftrue=(&n_pairs=4),
62 desc=Checking that every descendant of the parent is returned,
63 outds=work.test_results
64)
65
66%mp_assert(
67 iftrue=(&n_deep=1),
68 desc=Checking that the deepest child is reached,
69 outds=work.test_results
70)
71
72%mp_assert(
73 iftrue=(&n_total=6 and &n_root=1 and &n_23=1 and &n_24=1
74 and &n_35=1 and &n_leaf4=1 and &n_leaf5=1),
75 desc=Checking exact mp_recursivejoin rows levels and leaves,
76 outds=work.test_results
77)
78
79options &recursive_saved_obs &recursive_saved_firstobs;