Loading...
Searching...
No Matches
restore.test.2.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief testing restore of a change to a special missing value
4
5 @details A cell holding a special missing (._ .A-.Z) and changed to an
6 ordinary number must be reverted to that special missing. mp_stripdiffs
7 writes the old value into a generated UPDATE statement, and PUT drops the
8 leading period of a special missing, so the statement used to be
9 "set SOME_BESTNUM =_" - which PROC SQL reads as a column name.
10
11 <h4> SAS Macros </h4>
12 @li mp_assert.sas
13 @li mx_execute.sas
14
15**/
16
17%let _program=&appLoc/services/editors/restore;
18
19/* seed the base table with a special missing - the audit stores whatever the
20 base holds, so this is the value the revert has to write back */
21proc sql noprint;
22update &dclib..mpe_x_test set some_bestnum=._
23 where primary_key_field=3;
24quit;
25
26/**
27 * load 1 - change that cell to an ordinary number
28 */
29data work.sascontroltable;
30 action='LOAD';
31 message="special missing prep";
32 libds="&dclib..MPE_X_TEST";
33 output;
34 stop;
35run;
36
37data work.jsdata;
38 set &dclib..mpe_x_test(where=(primary_key_field=3)
39 rename=(some_date=dt2 SOME_DATETIME=dttm2 SOME_TIME=tm2)
40 );
41 /* the adapter sends these as strings */
42 some_date=put(dt2,date9.);
43 SOME_DATETIME=put(dttm2,datetime19.);
44 some_time=put(tm2,time.);
45 drop dt2 dttm2 tm2;
46 _____DELETE__THIS__RECORD_____='No';
47 some_bestnum=42;
48run;
49
50%mx_execute(&appLoc/services/editors/stagedata,
51 viyacontext=&defaultcontext,
52 inputdatasets=work.jsdata work.sascontroltable,
53 outlib=web1,
54 mdebug=&sasjs_mdebug
55)
56
57%let status=0;
58data _null_;
59 set web1.sasparams;
60 if status='SUCCESS' then call symputx('status',1);
61 call symputx('dsid',dsid);
62run;
63%mp_assert(
64 iftrue=(&status=1 and &syscc=0),
65 desc=Checking the special missing change was staged,
66 outds=work.test_results
67)
68
69data work.sascontroltable;
70 ACTION='APPROVE_TABLE';
71 TABLE="&dsid";
72 DIFFTIME="%sysfunc(datetime())";
73 output;
74 stop;
75run;
76%mx_execute(&appLoc/services/auditors/postdata,
77 viyacontext=&defaultcontext,
78 inputdatasets=work.sascontroltable,
79 outlib=web3,
80 outref=wb3,
81 mdebug=&sasjs_mdebug
82)
83
84%let status=0;
85data _null_;
86 set web3.apparams;
87 if response='SUCCESS!' then call symputx('status',1);
88run;
89%mp_assert(
90 iftrue=(&status=1 and &syscc=0),
91 desc=Checking the change was approved,
92 outds=work.test_results
93)
94
95/* the load reference to revert */
96%let loadref=0;
97data _null_;
98 set &dclib..mpe_submit end=last;
99 if last then call symputx('loadref',table_id);
100run;
101
102/**
103 * revert it - the old value in the diff is the special missing
104 */
105data work.restore_in;
106 load_ref="&loadref";
107 output;
108 stop;
109run;
110%mx_execute(&_program,
111 viyacontext=&defaultcontext,
112 inputdatasets=work.restore_in,
113 outlib=web1,
114 mdebug=&sasjs_mdebug
115)
116
117%let newref=0;
118data _null_;
119 set web1.restore_out;
120 call symputx('newref',loadref);
121run;
122%mp_assert(
123 iftrue=(&newref ne 0 and &syscc=0),
124 desc=Checking the revert was submitted,
125 outds=work.test_results
126)
127
128/* approve the reversion */
129data work.sascontroltable;
130 ACTION='APPROVE_TABLE';
131 TABLE="&newref";
132 DIFFTIME="%sysfunc(datetime())";
133 output;
134 stop;
135run;
136%mx_execute(&appLoc/services/auditors/postdata,
137 viyacontext=&defaultcontext,
138 inputdatasets=work.sascontroltable,
139 outlib=web3,
140 outref=wb3,
141 mdebug=&sasjs_mdebug
142)
143
144%let status=0;
145data _null_;
146 set web3.apparams;
147 if response='SUCCESS!' then call symputx('status',1);
148run;
149%mp_assert(
150 iftrue=(&status=1 and &syscc=0),
151 desc=Checking the reversion was approved,
152 outds=work.test_results
153)
154
155/* and the cell is back to the special missing, not a number and not blank */
156%let spmcheck=0;
157data _null_;
158 set &dclib..mpe_x_test(where=(primary_key_field=3));
159 if some_bestnum=._ then call symputx('spmcheck',1);
160 putlog some_bestnum=;
161run;
162%mp_assert(
163 iftrue=(&spmcheck=1),
164 desc=Checking the special missing was restored,
165 outds=work.test_results
166)
167
168/* put the fixture back as makedata left it */
169proc sql noprint;
170update &dclib..mpe_x_test set some_bestnum=44
171 where primary_key_field=3;
172quit;