Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_stackdiffs.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_storediffs macro
4
5 <h4> SAS Macros </h4>
6 @li mp_assert.sas
7 @li mp_assertcolvals.sas
8 @li mp_assertdsobs.sas
9 @li mp_assertscope.sas
10 @li mp_stackdiffs.sas
11 @li mp_storediffs.sas
12
13**/
14
15/* first, make some data */
16
17data work.orig work.deleted work.changed work.appended;
18 set sashelp.electric;
19 if _n_ le 10 then do;
20 output work.deleted;
21 end;
22 else if _n_ le 20 then do;
23 output work.orig;
24 coal=-1;
25 coaltip='modified';
26 output work.changed;
27 end;
28 else if _n_ le 30 then do;
29 year=_n_;
30 output work.appended;
31 end;
32 else stop;
33run;
34
35%mp_storediffs(sashelp.electric
36 ,work.orig
37 ,CUSTOMER YEAR
38 ,delds=work.deleted
39 ,modds=work.changed
40 ,appds=work.appended
41 ,outds=work.final
42 ,mdebug=1
43)
44
45
46%mp_assertscope(SNAPSHOT)
47
48/**
49 * Deletions test - where record does exist
50 */
51data work.orig1;
52 set sashelp.electric;
53 if _n_ le 10;
54run;
55data work.final1;
56 set work.final;
57 where move_type='D';
58run;
59%mp_stackdiffs(work.orig1
60 ,work.final1
61 ,CUSTOMER YEAR
62 ,mdebug=1
63 ,errds=work.errds1
64 ,outmod=work.mod1
65 ,outadd=work.add1
66 ,outdel=work.del1
67)
68%mp_assertdsobs(work.errds1,
69 desc=Delete1 - no errs,
70 test=EQUALS 0
71)
72%mp_assertdsobs(work.del1,
73 desc=Delete1 - records populated,
74 test=EQUALS 10
75)
76/**
77 * Deletions test - where record does NOT exist
78 */
79data work.orig2;
80 set work.orig;
81 stop; /* empty table */
82run;
83data work.final2;
84 set work.final;
85 where move_type='D';
86run;
87%mp_stackdiffs(work.orig2
88 ,work.final2
89 ,CUSTOMER YEAR
90 ,mdebug=1
91 ,errds=work.errds2
92 ,outmod=work.mod2
93 ,outadd=work.add2
94 ,outdel=work.del2
95)
96%mp_assertdsobs(work.errds2,
97 desc=Delete2 - has errs,
98 test=EQUALS 10
99)
100%mp_assertdsobs(work.del2,
101 desc=Delete2 - records not populated,
102 test=EQUALS 0
103)
104
105/**
106 * Additions test - where record does not exist
107 */
108data work.orig3;
109 set work.orig;
110 stop;
111run;
112data work.final3;
113 set work.final;
114 where move_type='A';
115run;
116%mp_stackdiffs(work.orig3
117 ,work.final3
118 ,CUSTOMER YEAR
119 ,mdebug=1
120 ,errds=work.errds3
121 ,outmod=work.mod3
122 ,outadd=work.add3
123 ,outdel=work.del3
124)
125%mp_assertdsobs(work.errds3,
126 desc=Add3 - no errs,
127 test=EQUALS 0
128)
129%mp_assertdsobs(work.add3,
130 desc=Add3 - records populated,
131 test=EQUALS 10
132)
133
134/**
135 * Additions test - where record does exist
136 */
137data work.orig4;
138 set sashelp.electric;
139 if _n_ ge 20;
140 year=_n_;
141 if _n_>25 then stop;
142run;
143data work.final4;
144 set work.final;
145 where move_type='A';
146run;
147%mp_stackdiffs(work.orig4
148 ,work.final4
149 ,CUSTOMER YEAR
150 ,mdebug=1
151 ,errds=work.errds4
152 ,outmod=work.mod4
153 ,outadd=work.add4
154 ,outdel=work.del4
155)
156%mp_assertdsobs(work.errds4,
157 desc=Add4 - 5 errs,
158 test=EQUALS 5
159)
160%mp_assertdsobs(work.add4,
161 desc=Add4 - records populated,
162 test=EQUALS 5
163)
164
165/**
166 * Additions test - where base table has missing vars
167 */
168data work.orig5;
169 set work.orig;
170 drop Coal;
171run;
172data work.final5;
173 set work.final;
174 where move_type='A';
175run;
176%mp_stackdiffs(work.orig5
177 ,work.final5
178 ,CUSTOMER YEAR
179 ,mdebug=1
180 ,errds=work.errds5
181 ,outmod=work.mod5
182 ,outadd=work.add5
183 ,outdel=work.del5
184)
185%mp_assertdsobs(work.errds5,
186 desc=Add5 - 10 errs,
187 test=EQUALS 10
188)
189%mp_assertdsobs(work.add5,
190 desc=Add5 - 0 records populated due to structure change,
191 test=EQUALS 0
192)
193
194/**
195 * Additions test - where append table has missing vars
196 */
197data work.final6;
198 set work.final;
199 where tgtvar_nm ne 'COAL' and move_type='A';
200run;
201%mp_stackdiffs(work.orig
202 ,work.final6
203 ,CUSTOMER YEAR
204 ,mdebug=1
205 ,errds=work.errds6
206 ,outmod=work.mod6
207 ,outadd=work.add6
208 ,outdel=work.del6
209)
210%mp_assertdsobs(work.errds6,
211 desc=Add6 - 0 errs,
212 test=EQUALS 0
213)
214%mp_assertdsobs(work.add6,
215 desc=Add6 - 10 records populated (structure change irrelevant),
216 test=EQUALS 10
217)
218
219/**
220 * Modifications test - where base table has missing vars
221 */
222data work.orig7;
223 set work.orig;
224 drop Coal;
225run;
226data work.final7;
227 set work.final;
228 where move_type='M';
229run;
230%mp_stackdiffs(work.orig7
231 ,work.final7
232 ,CUSTOMER YEAR
233 ,mdebug=1
234 ,errds=work.errds7
235 ,outmod=work.mod7
236 ,outadd=work.add7
237 ,outdel=work.del7
238)
239%mp_assertdsobs(work.errds7,
240 desc=Mod7 - 10 errs,
241 test=EQUALS 10
242)
243%mp_assertdsobs(work.Mod7,
244 desc=Mod7 - 0 records populated (structure change relevant),
245 test=EQUALS 0
246)
247%mp_assertdsobs(work.add7,
248 desc=add7 - 0 records populated ,
249 test=EQUALS 0
250)
251%mp_assertdsobs(work.del7,
252 desc=del7 - 0 records populated ,
253 test=EQUALS 0
254)
255/**
256 * Modifications (big) test - where base table has missing rows
257 * Also used as a full integration test (all move_types)
258 * And a test if the actual values were applied
259 */
260data work.orig8;
261 set sashelp.electric;
262 if _n_ le 16;
263run;
264%mp_stackdiffs(work.orig8
265 ,work.final
266 ,CUSTOMER YEAR
267 ,mdebug=1
268 ,errds=work.errds8
269 ,outmod=work.mod8
270 ,outadd=work.add8
271 ,outdel=work.del8
272)
273%mp_assertdsobs(work.errds8,
274 desc=Mod4 - 4 errs,
275 test=EQUALS 4
276)
277%mp_assertdsobs(work.Mod8,
278 desc=Mod8 - 6 records populated (missing rows relevant),
279 test=EQUALS 6
280)
281
282/**
283 * Modifications test - were diffs actually applied?
284 */
285data work.checkds;
286 charchk='modified';
287 numchk=-1;
288 output;
289run;
290%mp_assertcolvals(work.mod8.coal,
291 checkvals=work.checkds.numchk,
292 desc=Modified numeric value matches,
293 test=ALLVALS
294)
295%mp_assertcolvals(work.mod8.coaltip,
296 checkvals=work.checkds.charchk,
297 desc=Modified char value matches,
298 test=ALLVALS
299)
300
301
302%mp_assertscope(COMPARE,ignorelist=SASJS_FUNCTIONS)