@sasjs/core 4.50.0 → 4.51.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_stackdiffs.sas +1 -0
- package/base/mp_storediffs.sas +2 -1
- package/base/mp_stripdiffs.sas +224 -0
- package/meta/mm_getgroups.sas +5 -4
- package/package.json +1 -1
- package/xplatform/mx_getgroups.sas +16 -1
package/base/mp_stackdiffs.sas
CHANGED
|
@@ -197,6 +197,7 @@
|
|
|
197
197
|
@li mp_coretable.sas
|
|
198
198
|
@li mp_stackdiffs.test.sas
|
|
199
199
|
@li mp_storediffs.sas
|
|
200
|
+
@li mp_stripdiffs.sas
|
|
200
201
|
|
|
201
202
|
@todo The current approach assumes that a variable called KEY_HASH is not on
|
|
202
203
|
the base table. This part will need to be refactored (eg using
|
package/base/mp_storediffs.sas
CHANGED
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
<h4> Related Macros </h4>
|
|
65
65
|
@li mp_stackdiffs.sas
|
|
66
66
|
@li mp_storediffs.test.sas
|
|
67
|
+
@li mp_stripdiffs.sas
|
|
67
68
|
|
|
68
69
|
@version 9.2
|
|
69
70
|
@author Allan Bowe
|
|
@@ -183,7 +184,7 @@ data &ds4;
|
|
|
183
184
|
run;
|
|
184
185
|
|
|
185
186
|
%if "&loadref"="0" %then %let loadref=%sysfunc(uuidgen());
|
|
186
|
-
%if &processed_dttm=0 %then %let processed_dttm=%sysfunc(datetime());
|
|
187
|
+
%if &processed_dttm=0 %then %let processed_dttm=%sysfunc(datetime(),8.6);
|
|
187
188
|
%let libds=%upcase(&libds);
|
|
188
189
|
|
|
189
190
|
/* join orig vals for modified & deleted */
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Generates a stage dataset to revert diffs tracked in an audit table
|
|
4
|
+
@details A big benefit of tracking data changes in an audit table is that
|
|
5
|
+
those changes can be subsequently reverted if necessary!
|
|
6
|
+
|
|
7
|
+
This macro prepares a staging dataset containing those differences - eg for:
|
|
8
|
+
|
|
9
|
+
@li deleted rows - these are re-inserted
|
|
10
|
+
@li changed rows - differences are reverted
|
|
11
|
+
@li added rows - these are marked with `_____DELETE_THIS_RECORD_____="YES"`
|
|
12
|
+
|
|
13
|
+
These changes are NOT applied to the base table - a staging dataset is
|
|
14
|
+
simply prepared for an ETL process to action. In Data Controller, this
|
|
15
|
+
dataset is used directly as an input to the APPROVE process (so that the
|
|
16
|
+
reversion diffs can be reviewed prior to being applied).
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@param [in] libds Base library.dataset (will not be modified). The library
|
|
20
|
+
must be assigned.
|
|
21
|
+
@param [in] loadref Unique identifier for the version to be reverted. This
|
|
22
|
+
change, plus ALL SUBSEQUENT CHANGES, will be reverted in the output table.
|
|
23
|
+
@param [in] difftable The dataset containing the diffs. Definition available
|
|
24
|
+
in mddl_dc_difftable.sas
|
|
25
|
+
@param [out] outds= (work.mp_stripdiffs) Output table containing the diffs.
|
|
26
|
+
Has the same format as the base datset, plus a
|
|
27
|
+
`_____DELETE_THIS_RECORD_____` variable.
|
|
28
|
+
@param [in] mdebug= set to 1 to enable DEBUG messages and preserve outputs
|
|
29
|
+
|
|
30
|
+
<h4> SAS Macros </h4>
|
|
31
|
+
@li mf_getuniquefileref.sas
|
|
32
|
+
@li mf_getuniquename.sas
|
|
33
|
+
@li mf_islibds.sas
|
|
34
|
+
@li mp_abort.sas
|
|
35
|
+
|
|
36
|
+
<h4> Related Macros </h4>
|
|
37
|
+
@li mddl_dc_difftable.sas
|
|
38
|
+
@li mp_stackdiffs.sas
|
|
39
|
+
@li mp_storediffs.sas
|
|
40
|
+
@li mp_stripdiffs.test.sas
|
|
41
|
+
|
|
42
|
+
@version 9.2
|
|
43
|
+
@author Allan Bowe
|
|
44
|
+
**/
|
|
45
|
+
/** @cond */
|
|
46
|
+
|
|
47
|
+
%macro mp_stripdiffs(libds
|
|
48
|
+
,loadref
|
|
49
|
+
,difftable
|
|
50
|
+
,outds=work.mp_stripdiffs
|
|
51
|
+
,mdebug=0
|
|
52
|
+
)/*/STORE SOURCE*/;
|
|
53
|
+
%local dbg;
|
|
54
|
+
%if &mdebug=1 %then %do;
|
|
55
|
+
%put &sysmacroname entry vars:;
|
|
56
|
+
%put _local_;
|
|
57
|
+
%end;
|
|
58
|
+
%else %let dbg=*;
|
|
59
|
+
|
|
60
|
+
%let libds=%upcase(&libds);
|
|
61
|
+
|
|
62
|
+
/* safety checks */
|
|
63
|
+
%mp_abort(iftrue= (&syscc ne 0)
|
|
64
|
+
,mac=&sysmacroname
|
|
65
|
+
,msg=%str(SYSCC=&syscc on entry. Clean session required!)
|
|
66
|
+
)
|
|
67
|
+
%let libds=%upcase(&libds);
|
|
68
|
+
%mp_abort(iftrue= (%mf_islibds(&libds)=0)
|
|
69
|
+
,mac=&sysmacroname
|
|
70
|
+
,msg=%str(Invalid library.dataset reference - %superq(libds))
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
/* set up unique and temporary vars */
|
|
76
|
+
%local ds1 ds2 ds3 ds4 ds5 fref1;
|
|
77
|
+
%let fref1=%mf_getuniquefileref();
|
|
78
|
+
|
|
79
|
+
/* get timestamp of the diff to be reverted */
|
|
80
|
+
%local ts;
|
|
81
|
+
proc sql noprint;
|
|
82
|
+
select put(processed_dttm,datetime19.6) into: ts
|
|
83
|
+
from &difftable where load_ref="&loadref";
|
|
84
|
+
%mp_abort(iftrue= (&sqlobs=0)
|
|
85
|
+
,mac=&sysmacroname
|
|
86
|
+
,msg=%str(Load ref %superq(loadref) not found!)
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
/* extract diffs for this base table from this timestamp onwards */
|
|
90
|
+
%let ds1=%upcase(work.%mf_getuniquename(prefix=mpsd_diffs));
|
|
91
|
+
create table &ds1 (drop=libref dsn) as
|
|
92
|
+
select * from &difftable
|
|
93
|
+
where upcase(cats(libref))="%scan(&libds,1,.)"
|
|
94
|
+
and upcase(cats(dsn))="%scan(&libds,2,.)"
|
|
95
|
+
and processed_dttm ge "&ts"dt
|
|
96
|
+
order by processed_dttm desc, key_hash, is_pk;
|
|
97
|
+
|
|
98
|
+
/* extract key values only */
|
|
99
|
+
%let ds2=%upcase(work.%mf_getuniquename(prefix=mpsd_pks));
|
|
100
|
+
create table &ds2 as
|
|
101
|
+
select key_hash,
|
|
102
|
+
tgtvar_nm,
|
|
103
|
+
tgtvar_type,
|
|
104
|
+
coalescec(oldval_char,newval_char) as charval,
|
|
105
|
+
coalesce(oldval_num, newval_num) as numval,
|
|
106
|
+
processed_dttm
|
|
107
|
+
from &ds1
|
|
108
|
+
where is_pk=1
|
|
109
|
+
order by key_hash, processed_dttm;
|
|
110
|
+
|
|
111
|
+
/* grab pk values */
|
|
112
|
+
%local pk;
|
|
113
|
+
data _null_;
|
|
114
|
+
set &ds2;
|
|
115
|
+
by key_hash;
|
|
116
|
+
call symputx('pk',catx(' ',symget('pk'),tgtvar_nm),'l');
|
|
117
|
+
if last.key_hash then stop;
|
|
118
|
+
run;
|
|
119
|
+
|
|
120
|
+
%let ds3=%upcase(work.%mf_getuniquename(prefix=mpsd_keychar));
|
|
121
|
+
proc transpose data=&ds2(where=(tgtvar_type='C'))
|
|
122
|
+
out=&ds3(drop=_name_);
|
|
123
|
+
by KEY_HASH;
|
|
124
|
+
id TGTVAR_NM;
|
|
125
|
+
var charval;
|
|
126
|
+
run;
|
|
127
|
+
|
|
128
|
+
%let ds4=%upcase(work.%mf_getuniquename(prefix=mpsd_keynum));
|
|
129
|
+
proc transpose data=&ds2(where=(tgtvar_type='N'))
|
|
130
|
+
out=&ds4(drop=_name_);
|
|
131
|
+
by KEY_HASH;
|
|
132
|
+
id TGTVAR_NM;
|
|
133
|
+
var numval;
|
|
134
|
+
run;
|
|
135
|
+
/* shorten the lengths */
|
|
136
|
+
%mp_ds2squeeze(&ds3,outds=&ds3)
|
|
137
|
+
%mp_ds2squeeze(&ds4,outds=&ds4)
|
|
138
|
+
|
|
139
|
+
%let ds5=%upcase(work.%mf_getuniquename(prefix=mpsd_merged));
|
|
140
|
+
data &ds5;
|
|
141
|
+
merge &ds3 &ds4;
|
|
142
|
+
by key_hash;
|
|
143
|
+
if not missing(key_hash);
|
|
144
|
+
run;
|
|
145
|
+
|
|
146
|
+
/* join to base table for preliminary stage DS */
|
|
147
|
+
proc sql;
|
|
148
|
+
create table &outds as select "No " as _____DELETE_THIS_RECORD_____,
|
|
149
|
+
b.*
|
|
150
|
+
from &ds5 a
|
|
151
|
+
inner join &libds b
|
|
152
|
+
on 1=1
|
|
153
|
+
%do x=1 %to %sysfunc(countw(&pk,%str( )));
|
|
154
|
+
and a.%scan(&pk,&x,%str( ))=b.%scan(&pk,&x,%str( ))
|
|
155
|
+
%end;
|
|
156
|
+
;
|
|
157
|
+
|
|
158
|
+
/* create SAS code to apply to stage_ds */
|
|
159
|
+
data _null_;
|
|
160
|
+
set &ds1;
|
|
161
|
+
file &fref1;
|
|
162
|
+
if _n_=1 then put 'proc sql noprint;';
|
|
163
|
+
by descending processed_dttm key_hash is_pk;
|
|
164
|
+
if move_type='M' then do;
|
|
165
|
+
if first.key_hash then do;
|
|
166
|
+
put "update &outds set " @@;
|
|
167
|
+
end;
|
|
168
|
+
if IS_PK=0 then do;
|
|
169
|
+
put " " tgtvar_nm '=' @@;
|
|
170
|
+
charval=quote(cats(oldval_char));
|
|
171
|
+
if tgtvar_type='C' then put charval @@;
|
|
172
|
+
else put oldval_num @@;
|
|
173
|
+
if not last.is_pk then put ',';
|
|
174
|
+
end;
|
|
175
|
+
else do;
|
|
176
|
+
if first.is_pk then put " where 1=1 " @@;
|
|
177
|
+
put " and " tgtvar_nm '=' @@;
|
|
178
|
+
charval=quote(cats(oldval_char));
|
|
179
|
+
if tgtvar_type='C' then put charval @@;
|
|
180
|
+
else put oldval_num @@;
|
|
181
|
+
end;
|
|
182
|
+
end;
|
|
183
|
+
else if move_type='A' then do;
|
|
184
|
+
if first.key_hash then do;
|
|
185
|
+
put "update &outds set _____DELETE_THIS_RECORD_____='Yes' where 1=1 " @@;
|
|
186
|
+
end;
|
|
187
|
+
/* gating if - as only need PK now */
|
|
188
|
+
if is_pk=1;
|
|
189
|
+
put ' AND ' tgtvar_nm '=' @@;
|
|
190
|
+
charval=quote(cats(newval_char));
|
|
191
|
+
if tgtvar_type='C' then put charval @@;
|
|
192
|
+
else put newval_num @@;
|
|
193
|
+
end;
|
|
194
|
+
else if move_type='D' then do;
|
|
195
|
+
if first.key_hash then do;
|
|
196
|
+
put "insert into &outds set _____DELETE_THIS_RECORD_____='No' " @@;
|
|
197
|
+
end;
|
|
198
|
+
put " ," tgtvar_nm '=' @@;
|
|
199
|
+
charval=quote(cats(oldval_char));
|
|
200
|
+
if tgtvar_type='C' then put charval @@;
|
|
201
|
+
else put oldval_num @@;
|
|
202
|
+
end;
|
|
203
|
+
if last.key_hash then put ';';
|
|
204
|
+
run;
|
|
205
|
+
|
|
206
|
+
/* apply the modification statements */
|
|
207
|
+
%inc &fref1/source2;
|
|
208
|
+
|
|
209
|
+
%if &mdebug=0 %then %do;
|
|
210
|
+
proc sql;
|
|
211
|
+
drop table &ds1, &ds2, &ds3, &ds4, &ds5;
|
|
212
|
+
file &fref1 clear;
|
|
213
|
+
%end;
|
|
214
|
+
%else %do;
|
|
215
|
+
data _null_;
|
|
216
|
+
infile &fref1;
|
|
217
|
+
input;
|
|
218
|
+
if _n_=1 then putlog "Contents of SQL adjustments";
|
|
219
|
+
putlog _infile_;
|
|
220
|
+
run;
|
|
221
|
+
%end;
|
|
222
|
+
|
|
223
|
+
%mend mp_stripdiffs;
|
|
224
|
+
/** @endcond */
|
package/meta/mm_getgroups.sas
CHANGED
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
|
|
12
12
|
@param [in] user= the metadata user to return groups for. Leave blank for all
|
|
13
13
|
groups.
|
|
14
|
-
@param [in] repo= the metadata repository that contains the
|
|
15
|
-
information
|
|
16
|
-
@param [in] mDebug= set to 1 to show debug messages in the log
|
|
17
|
-
@param [out] outds=
|
|
14
|
+
@param [in] repo= (foundation) the metadata repository that contains the
|
|
15
|
+
user/group information
|
|
16
|
+
@param [in] mDebug= (0) set to 1 to show debug messages in the log
|
|
17
|
+
@param [out] outds= (work.mm_getgroups) The dataset to create that contains
|
|
18
|
+
the list of groups
|
|
18
19
|
|
|
19
20
|
@returns outds dataset containing all groups in a column named "metagroup"
|
|
20
21
|
- groupuri
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
Valid values are "password" or "authorization_code" (unquoted).
|
|
21
21
|
@param [out] outds= (work.mx_getgroups) This output dataset will contain the
|
|
22
22
|
list of groups. Format:
|
|
23
|
-
|
|
|
23
|
+
|GROUPNAME:$32.|GROUPDESC:$256.|GROUPURI:best.|
|
|
24
24
|
|---|---|---|
|
|
25
25
|
|`SomeGroup `|`A group `|`1`|
|
|
26
26
|
|`Another Group`|`this is a different group`|`2`|
|
|
@@ -54,6 +54,15 @@
|
|
|
54
54
|
outds=&outds,
|
|
55
55
|
mdebug=&mdebug
|
|
56
56
|
)
|
|
57
|
+
data &outds;
|
|
58
|
+
length groupuri groupname $32 groupdesc $128 ;
|
|
59
|
+
set &outds;
|
|
60
|
+
keep groupuri groupname groupdesc;
|
|
61
|
+
groupuri=cats(groupid);
|
|
62
|
+
groupname=name;
|
|
63
|
+
groupdesc=description;
|
|
64
|
+
run;
|
|
65
|
+
proc sort; by groupname; run;
|
|
57
66
|
%end;
|
|
58
67
|
%else %if &platform=SAS9 or &platform=SASMETA %then %do;
|
|
59
68
|
%if &user=0 %then %let user=;
|
|
@@ -63,6 +72,7 @@
|
|
|
63
72
|
,repo=&repo
|
|
64
73
|
,mDebug=&mdebug
|
|
65
74
|
)
|
|
75
|
+
proc sort data=&outds; by groupname; run;
|
|
66
76
|
%end;
|
|
67
77
|
%else %if &platform=SASVIYA %then %do;
|
|
68
78
|
%if &user=0 %then %do;
|
|
@@ -78,6 +88,11 @@
|
|
|
78
88
|
,grant_type=&grant_type
|
|
79
89
|
)
|
|
80
90
|
%end;
|
|
91
|
+
proc sort
|
|
92
|
+
data=&outds(rename=(id=groupuri name=groupname description=groupdesc))
|
|
93
|
+
out=&outds (keep=groupuri groupname groupdesc);
|
|
94
|
+
by groupname;
|
|
95
|
+
run;
|
|
81
96
|
%end;
|
|
82
97
|
|
|
83
98
|
%mend mx_getgroups;
|