@sasjs/core 4.51.5 → 4.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base/mp_stripdiffs.sas +47 -26
- package/package.json +1 -1
package/base/mp_stripdiffs.sas
CHANGED
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
change, plus ALL SUBSEQUENT CHANGES, will be reverted in the output table.
|
|
23
23
|
@param [in] difftable The dataset containing the diffs. Definition available
|
|
24
24
|
in mddl_dc_difftable.sas
|
|
25
|
+
@param [in] filtervar= (0) If provided, the contents of this macro variable
|
|
26
|
+
will be applied as an additional filter against &libds
|
|
25
27
|
@param [out] outds= (work.mp_stripdiffs) Output table containing the diffs.
|
|
26
28
|
Has the same format as the base datset, plus a
|
|
27
29
|
`_____DELETE__THIS__RECORD_____` variable.
|
|
@@ -30,7 +32,9 @@
|
|
|
30
32
|
<h4> SAS Macros </h4>
|
|
31
33
|
@li mf_getuniquefileref.sas
|
|
32
34
|
@li mf_getuniquename.sas
|
|
35
|
+
@li mf_getvarlist.sas
|
|
33
36
|
@li mf_islibds.sas
|
|
37
|
+
@li mf_wordsinstr1butnotstr2.sas
|
|
34
38
|
@li mp_abort.sas
|
|
35
39
|
|
|
36
40
|
<h4> Related Macros </h4>
|
|
@@ -47,6 +51,7 @@
|
|
|
47
51
|
%macro mp_stripdiffs(libds
|
|
48
52
|
,loadref
|
|
49
53
|
,difftable
|
|
54
|
+
,filtervar=0
|
|
50
55
|
,outds=work.mp_stripdiffs
|
|
51
56
|
,mdebug=0
|
|
52
57
|
)/*/STORE SOURCE*/;
|
|
@@ -70,11 +75,11 @@
|
|
|
70
75
|
,msg=%str(Invalid library.dataset reference - %superq(libds))
|
|
71
76
|
)
|
|
72
77
|
|
|
73
|
-
|
|
74
|
-
|
|
75
78
|
/* set up unique and temporary vars */
|
|
76
|
-
%local ds1 ds2 ds3 ds4 ds5 fref1;
|
|
79
|
+
%local ds1 ds2 ds3 ds4 ds5 fref1 filterstr;
|
|
77
80
|
%let fref1=%mf_getuniquefileref();
|
|
81
|
+
%if &filtervar ne 0 %then %let filterstr=%superq(&filtervar);
|
|
82
|
+
%else %let filterstr=%str(1=1);
|
|
78
83
|
|
|
79
84
|
/* get timestamp of the diff to be reverted */
|
|
80
85
|
%local ts;
|
|
@@ -97,30 +102,28 @@ create table &ds1 (drop=libref dsn) as
|
|
|
97
102
|
|
|
98
103
|
/* extract key values only */
|
|
99
104
|
%let ds2=%upcase(work.%mf_getuniquename(prefix=mpsd_pks));
|
|
105
|
+
%local keyhash processed;
|
|
106
|
+
%let keyhash=%upcase(%mf_getuniquename(prefix=mpsdvar_keyhash));
|
|
107
|
+
%let processed=%upcase(%mf_getuniquename(prefix=mpsdvar_processed));
|
|
100
108
|
create table &ds2 as
|
|
101
|
-
select
|
|
109
|
+
select key_hash as &keyhash,
|
|
102
110
|
tgtvar_nm,
|
|
103
111
|
tgtvar_type,
|
|
104
112
|
coalescec(oldval_char,newval_char) as charval,
|
|
105
113
|
coalesce(oldval_num, newval_num) as numval,
|
|
106
|
-
processed_dttm
|
|
114
|
+
processed_dttm as &processed
|
|
107
115
|
from &ds1
|
|
108
116
|
where is_pk=1
|
|
109
|
-
order by
|
|
117
|
+
order by &keyhash, &processed;
|
|
110
118
|
|
|
111
119
|
/* grab pk values */
|
|
112
120
|
%local pk;
|
|
113
|
-
|
|
114
|
-
set &ds2;
|
|
115
|
-
by key_hash processed_dttm;
|
|
116
|
-
call symputx('pk',catx(' ',symget('pk'),tgtvar_nm),'l');
|
|
117
|
-
if last.processed_dttm then stop;
|
|
118
|
-
run;
|
|
121
|
+
select distinct upcase(tgtvar_nm) into: pk separated by ' ' from &ds2;
|
|
119
122
|
|
|
120
123
|
%let ds3=%upcase(work.%mf_getuniquename(prefix=mpsd_keychar));
|
|
121
124
|
proc transpose data=&ds2(where=(tgtvar_type='C'))
|
|
122
125
|
out=&ds3(drop=_name_);
|
|
123
|
-
by
|
|
126
|
+
by &keyhash &processed;
|
|
124
127
|
id TGTVAR_NM;
|
|
125
128
|
var charval;
|
|
126
129
|
run;
|
|
@@ -128,7 +131,7 @@ run;
|
|
|
128
131
|
%let ds4=%upcase(work.%mf_getuniquename(prefix=mpsd_keynum));
|
|
129
132
|
proc transpose data=&ds2(where=(tgtvar_type='N'))
|
|
130
133
|
out=&ds4(drop=_name_);
|
|
131
|
-
by
|
|
134
|
+
by &keyhash &processed;
|
|
132
135
|
id TGTVAR_NM;
|
|
133
136
|
var numval;
|
|
134
137
|
run;
|
|
@@ -139,10 +142,10 @@ run;
|
|
|
139
142
|
/* now merge to get all key values and de-dup */
|
|
140
143
|
%let ds5=%upcase(work.%mf_getuniquename(prefix=mpsd_merged));
|
|
141
144
|
data &ds5;
|
|
142
|
-
length
|
|
145
|
+
length &keyhash $32 &processed 8;
|
|
143
146
|
merge &ds3 &ds4;
|
|
144
|
-
by
|
|
145
|
-
if not missing(
|
|
147
|
+
by &keyhash &processed;
|
|
148
|
+
if not missing(&keyhash);
|
|
146
149
|
run;
|
|
147
150
|
proc sort data=&ds5 nodupkey;
|
|
148
151
|
by &pk;
|
|
@@ -150,10 +153,18 @@ run;
|
|
|
150
153
|
|
|
151
154
|
/* join to base table for preliminary stage DS */
|
|
152
155
|
proc sql;
|
|
153
|
-
create table &outds as select "No " as _____DELETE__THIS__RECORD_____
|
|
154
|
-
|
|
156
|
+
create table &outds as select "No " as _____DELETE__THIS__RECORD_____
|
|
157
|
+
%do x=1 %to %sysfunc(countw(&pk,%str( )));
|
|
158
|
+
,a.%scan(&pk,&x,%str( ))
|
|
159
|
+
%end;
|
|
160
|
+
%local notpkcols;
|
|
161
|
+
%let notpkcols=%upcase(%mf_getvarlist(&libds));
|
|
162
|
+
%let notpkcols=%mf_wordsinstr1butnotstr2(str1=¬pkcols,str2=&pk);
|
|
163
|
+
%do x=1 %to %sysfunc(countw(¬pkcols,%str( )));
|
|
164
|
+
,b.%scan(¬pkcols,&x,%str( ))
|
|
165
|
+
%end;
|
|
155
166
|
from &ds5 a
|
|
156
|
-
|
|
167
|
+
left join &libds (where=(&filterstr)) b
|
|
157
168
|
on 1=1
|
|
158
169
|
%do x=1 %to %sysfunc(countw(&pk,%str( )));
|
|
159
170
|
and a.%scan(&pk,&x,%str( ))=b.%scan(&pk,&x,%str( ))
|
|
@@ -202,13 +213,23 @@ data _null_;
|
|
|
202
213
|
end;
|
|
203
214
|
else if move_type='D' then do;
|
|
204
215
|
if first.key_hash then do;
|
|
205
|
-
put "
|
|
216
|
+
put "update &outds set _____DELETE__THIS__RECORD_____='No' " @@;
|
|
217
|
+
end;
|
|
218
|
+
if IS_PK=0 then do;
|
|
219
|
+
put " ," tgtvar_nm '=' @@;
|
|
220
|
+
cnt=count(oldval_char,'"');
|
|
221
|
+
charval=quote(trim(substr(oldval_char,1,32765-cnt)));
|
|
222
|
+
if tgtvar_type='C' then put charval @@;
|
|
223
|
+
else put oldval_num @@;
|
|
224
|
+
end;
|
|
225
|
+
else do;
|
|
226
|
+
if first.is_pk then put " where 1=1 " @@;
|
|
227
|
+
put " and " tgtvar_nm '=' @@;
|
|
228
|
+
cnt=count(oldval_char,'"');
|
|
229
|
+
charval=quote(trim(substr(oldval_char,1,32765-cnt)));
|
|
230
|
+
if tgtvar_type='C' then put charval @@;
|
|
231
|
+
else put oldval_num @@;
|
|
206
232
|
end;
|
|
207
|
-
put " ," tgtvar_nm '=' @@;
|
|
208
|
-
cnt=count(oldval_char,'"');
|
|
209
|
-
charval=quote(trim(substr(oldval_char,1,32765-cnt)));
|
|
210
|
-
if tgtvar_type='C' then put charval @@;
|
|
211
|
-
else put oldval_num @@;
|
|
212
233
|
end;
|
|
213
234
|
if last.key_hash then put ';';
|
|
214
235
|
run;
|
package/package.json
CHANGED