Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_stackdiffs.test.2.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_stackdiffs.sas macro with special missing values
4
5 <h4> SAS Macros </h4>
6 @li mp_assert.sas
7 @li mp_assertscope.sas
8 @li mp_stackdiffs.sas
9 @li mp_storediffs.sas
10
11**/
12
13/* re-applying a change means writing the new value into a PROC SQL statement,
14 so a special missing needs to survive as ._ / .A / .Z */
15libname libby (work);
16data libby.spm;
17 pknum=.A; grp='a'; score=2; output;
18 pknum=.Z; grp='b'; score=.B; output;
19 pknum=3; grp='c'; score=.Q; output;
20run;
21
22data work.orig work.changed;
23 set libby.spm;
24 output work.orig;
25 if pknum=.A then do;
26 score=._;
27 output work.changed;
28 end;
29 else if pknum=.Z then do;
30 score=.D;
31 output work.changed;
32 end;
33run;
34
35/* store the diffs, then re-apply them */
36%mp_storediffs(libby.spm,work.orig,PKNUM GRP
37 ,modds=work.changed
38 ,outds=work.audit
39 ,loadref=SPM2
40 ,mdebug=0
41)
42%mp_assert(
43 iftrue=(&syscc=0),
44 desc=Checking diffs were stored for special missing values,
45 outds=work.test_results
46)
47
48data work.st_mods;
49 set work.audit;
50 where move_type='M';
51run;
52
53%mp_assertscope(SNAPSHOT)
54%mp_stackdiffs(libby.spm
55 ,work.st_mods
56 ,PKNUM GRP
57 ,mdebug=1
58 ,errds=work.st_errds
59 ,outmod=work.st_outmod
60 ,outadd=work.st_outadd
61 ,outdel=work.st_outdel
62)
63%mp_assertscope(COMPARE)
64%mp_assert(
65 iftrue=(&syscc=0),
66 desc=Checking no failure when stacking special missing values,
67 outds=work.test_results
68)
69
70data work.st_expected;
71 pknum=.A; grp='a'; score=._; output;
72 pknum=.Z; grp='b'; score=.D; output;
73run;
74
75proc compare base=work.st_expected compare=work.st_outmod;
76run;
77data _null_;
78 /* data-relevant bits only: 64 missing obs, 128 extra obs, 4096 unequal
79 values, 32768 different number of observations */
80 call symputx('cmpfail',band(&sysinfo,64+128+4096+32768),'l');
81run;
82%mp_assert(
83 iftrue=(&cmpfail=0),
84 desc=Checking stacked values match the new values for special missings,
85 outds=work.test_results
86)