@sasjs/core 2.58.3 → 2.59.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.
@@ -70,5 +70,5 @@
70
70
  %put &sysmacroname: SYSMSG= %sysfunc(sysmsg());
71
71
  %let rc=%sysfunc(close(&dsid));
72
72
  %end;
73
- &outvar
73
+ %do;%unquote(&outvar)%end;
74
74
  %mend mf_getvarlist;
@@ -88,6 +88,7 @@ run;
88
88
  /* prepare the errds */
89
89
  data &errds;
90
90
  length msg mac $1000;
91
+ call missing(msg,mac);
91
92
  iftrue='1=0';
92
93
  run;
93
94
 
@@ -180,7 +180,7 @@ run;
180
180
  %else %do;
181
181
  data _null_;
182
182
  putlog 'NOTE-' / 'NOTE-';
183
- putlog "NOTE- &sysmacroname: Table &lib..&ds locked at "@
183
+ putlog "NOTE- &sysmacroname: Table &lib..&ds locked at "@;
184
184
  putlog " %sysfunc(datetime(),datetime19.) (iteration &x)"@;
185
185
  putlog 'NOTE-' / 'NOTE-';
186
186
  run;
@@ -0,0 +1,237 @@
1
+ /**
2
+ @file
3
+ @brief Converts deletes/changes/appends into a single audit table.
4
+ @details When tracking changes to data over time, it can be helpful to have
5
+ a single base table to track ALL modifications - enabling audit trail,
6
+ data recovery, and change re-application. This macro is one of many
7
+ data management utilities used in [Data Controller for SAS](
8
+ https:datacontroller.io) - a comprehensive data ingestion solution, which
9
+ works on any SAS platform (Viya, SAS 9, Foundation) and is free for up to 5
10
+ users.
11
+
12
+ NOTE - this macro does not validate the inputs. It is assumed that the
13
+ datasets containing the new / changed / deleted rows are CORRECT, contain
14
+ no additional (or missing columns), and that the originals dataset contains
15
+ all relevant base records (and no additionals).
16
+
17
+ Usage:
18
+
19
+ data work.orig work.deleted work.changed work.appended;
20
+ set sashelp.class;
21
+ if _n_=1 then do;
22
+ output work.orig work.deleted;
23
+ end;
24
+ else if _n_=2 then do;
25
+ output work.orig;
26
+ age=99;
27
+ output work.changed;
28
+ end;
29
+ else do;
30
+ name='Newbie';
31
+ output work.appended;
32
+ stop;
33
+ end;
34
+ run;
35
+
36
+ %mp_storediffs(sashelp.class,work.orig,NAME
37
+ ,delds=work.deleted
38
+ ,modds=work.changed
39
+ ,appds=work.appended
40
+ ,outds=work.final
41
+ ,mdebug=1
42
+ )
43
+
44
+ @param [in] libds Target table against which the changes were applied
45
+ @param [in] origds Dataset with original (unchanged) records. Can be empty if
46
+ only appending.
47
+ @param [in] key Space seperated list of key variables
48
+ @param [in] delds= (0) Dataset with deleted records
49
+ @param [in] appds= (0) Dataset with appended records
50
+ @param [in] modds= (0) Dataset with modified records
51
+ @param [out] outds= (work.mp_storediffs) Output table containing stored data.
52
+ Has the following format:
53
+
54
+ proc sql;
55
+ create table &outds(
56
+ load_ref char(36) label='unique load reference',
57
+ processed_dttm num format=E8601DT26.6 label='Processed at timestamp',
58
+ libref char(8) label='Library Reference (8 chars)',
59
+ dsn char(32) label='Dataset Name (32 chars)',
60
+ key_hash char(32) label=
61
+ 'MD5 Hash of primary key values (pipe seperated)',
62
+ move_type char(1) label='Either (A)ppended, (D)eleted or (M)odified',
63
+ is_pk num label='Is Primary Key Field? (1/0)',
64
+ is_diff num label=
65
+ 'Did value change? (1/0/-1). Always -1 for appends and deletes.',
66
+ tgtvar_type char(1) label='Either (C)haracter or (N)umeric',
67
+ tgtvar_nm char(32) label='Target variable name (32 chars)',
68
+ oldval_num num label='Old (numeric) value',
69
+ newval_num num label='New (numeric) value',
70
+ oldval_char char(32767) label='Old (character) value',
71
+ newval_char char(32767) label='New (character) value',
72
+ constraint pk_mpe_audit
73
+ primary key(load_ref,libref,dsn,key_hash,tgtvar_nm)
74
+ );
75
+
76
+ @param [in] processed_dttm= (0) Provide a datetime constant in relation to
77
+ the actual load time. If not provided, current timestamp is used.
78
+ @param [in] mdebug= set to 1 to enable DEBUG messages and preserve outputs
79
+ @param [out] loadref= (0) Provide a unique key to reference the load,
80
+ otherwise a UUID will be generated.
81
+
82
+ <h4> SAS Macros </h4>
83
+ @li mf_getquotedstr.sas
84
+ @li mf_getuniquename.sas
85
+ @li mf_getvarlist.sas
86
+
87
+ @version 9.2
88
+ @author Allan Bowe
89
+ **/
90
+ /** @cond */
91
+
92
+ %macro mp_storediffs(libds
93
+ ,origds
94
+ ,key
95
+ ,delds=0
96
+ ,appds=0
97
+ ,modds=0
98
+ ,outds=work.mp_storediffs
99
+ ,loadref=0
100
+ ,processed_dttm=0
101
+ ,mdebug=0
102
+ )/*/STORE SOURCE*/;
103
+ %local dbg;
104
+ %if &mdebug=1 %then %do;
105
+ %put &sysmacroname entry vars:;
106
+ %put _local_;
107
+ %end;
108
+ %else %let dbg=*;
109
+
110
+ /* set up unique and temporary vars */
111
+ %local ds1 ds2 ds3 ds4 hashkey inds_auto inds_keep dslist;
112
+ %let ds1=%upcase(work.%mf_getuniquename(prefix=mpsd_ds1));
113
+ %let ds2=%upcase(work.%mf_getuniquename(prefix=mpsd_ds2));
114
+ %let ds3=%upcase(work.%mf_getuniquename(prefix=mpsd_ds3));
115
+ %let ds4=%upcase(work.%mf_getuniquename(prefix=mpsd_ds4));
116
+ %let hashkey=%upcase(%mf_getuniquename(prefix=mpsd_hashkey));
117
+ %let inds_auto=%upcase(%mf_getuniquename(prefix=mpsd_inds_auto));
118
+ %let inds_keep=%upcase(%mf_getuniquename(prefix=mpsd_inds_keep));
119
+
120
+ %let dslist=&origds;
121
+ %if &delds ne 0 %then %do;
122
+ %let delds=%upcase(&delds);
123
+ %if %scan(&delds,-1,.)=&delds %then %let delds=WORK.&delds;
124
+ %let dslist=&dslist &delds;
125
+ %end;
126
+ %if &appds ne 0 %then %do;
127
+ %let appds=%upcase(&appds);
128
+ %if %scan(&appds,-1,.)=&appds %then %let appds=WORK.&appds;
129
+ %let dslist=&dslist &appds;
130
+ %end;
131
+ %if &modds ne 0 %then %do;
132
+ %let modds=%upcase(&modds);
133
+ %if %scan(&modds,-1,.)=&modds %then %let modds=WORK.&modds;
134
+ %let dslist=&dslist &modds;
135
+ %end;
136
+
137
+ %let origds=%upcase(&origds);
138
+ %if %scan(&origds,-1,.)=&origds %then %let origds=WORK.&origds;
139
+
140
+ %let key=%upcase(&key);
141
+
142
+ /* hash the key and append all the tables (marking the source) */
143
+ data &ds1;
144
+ set &dslist indsname=&inds_auto;
145
+ &hashkey=put(md5(catx('|',%mf_getquotedstr(&key,quote=N))),$hex32.);
146
+ &inds_keep=&inds_auto;
147
+ proc sort;
148
+ by &inds_keep &hashkey;
149
+ run;
150
+
151
+ /* transpose numeric & char vars */
152
+ proc transpose data=&ds1
153
+ out=&ds2(rename=(&hashkey=key_hash _name_=tgtvar_nm col1=newval_num));
154
+ by &inds_keep &hashkey;
155
+ var _numeric_;
156
+ run;
157
+ proc transpose data=&ds1
158
+ out=&ds3(
159
+ rename=(&hashkey=key_hash _name_=tgtvar_nm col1=newval_char)
160
+ where=(tgtvar_nm not in ("&hashkey","&inds_keep"))
161
+ );
162
+ by &inds_keep &hashkey;
163
+ var _character_;
164
+ run;
165
+ data &ds4;
166
+ length &inds_keep $41 tgtvar_nm $32;
167
+ set &ds2 &ds3 indsname=&inds_auto;
168
+
169
+ tgtvar_nm=upcase(tgtvar_nm);
170
+ if tgtvar_nm in (%upcase(%mf_getvarlist(&libds,dlm=%str(,),quote=DOUBLE)));
171
+
172
+ if &inds_auto="&ds2" then tgtvar_type='N';
173
+ else if &inds_auto="&ds3" then tgtvar_type='C';
174
+ else do;
175
+ putlog "%str(ERR)OR: unidentified vartype input!" &inds_auto;
176
+ call symputx('syscc',98);
177
+ end;
178
+
179
+ if &inds_keep="&appds" then move_type='A';
180
+ else if &inds_keep="&delds" then move_type='D';
181
+ else if &inds_keep="&modds" then move_type='M';
182
+ else if &inds_keep="&origds" then move_type='O';
183
+ else do;
184
+ putlog "%str(ERR)OR: unidentified movetype input!" &inds_keep;
185
+ call symputx('syscc',99);
186
+ end;
187
+ tgtvar_nm=upcase(tgtvar_nm);
188
+ if tgtvar_nm in (%mf_getquotedstr(&key)) then is_pk=1;
189
+ else is_pk=0;
190
+ drop &inds_keep;
191
+ run;
192
+
193
+ %if "&loadref"="0" %then %let loadref=%sysfunc(uuidgen());
194
+ %if &processed_dttm=0 %then %let processed_dttm=%sysfunc(datetime());
195
+ %let libds=%upcase(&libds);
196
+
197
+ /* join orig vals for modified & deleted */
198
+ proc sql;
199
+ create table &outds as
200
+ select "&loadref" as load_ref length=36
201
+ ,&processed_dttm as processed_dttm format=E8601DT26.6
202
+ ,"%scan(&libds,1,.)" as libref length=8
203
+ ,"%scan(&libds,2,.)" as dsn length=32
204
+ ,b.key_hash length=32
205
+ ,b.move_type length=1
206
+ ,b.tgtvar_nm length=32
207
+ ,b.is_pk
208
+ ,case when b.move_type ne 'M' then -1
209
+ when a.newval_num=b.newval_num and a.newval_char=b.newval_char then 0
210
+ else 1
211
+ end as is_diff
212
+ ,b.tgtvar_type length=1
213
+ ,case when b.move_type='D' then b.newval_num
214
+ else a.newval_num
215
+ end as oldval_num
216
+ ,case when b.move_type='D' then .
217
+ else b.newval_num
218
+ end as newval_num
219
+ ,case when b.move_type='D' then b.newval_char
220
+ else a.newval_char
221
+ end as oldval_char length=32767
222
+ ,case when b.move_type='D' then ''
223
+ else b.newval_char
224
+ end as newval_char length=32767
225
+ from &ds4(where=(move_type='O')) as a
226
+ full join &ds4(where=(move_type ne 'O')) as b
227
+ on a.tgtvar_nm=b.tgtvar_nm
228
+ and a.key_hash=b.key_hash
229
+ order by move_type, key_hash,is_pk desc, tgtvar_nm;
230
+
231
+ %if &mdebug=0 %then %do;
232
+ proc sql;
233
+ drop table &ds1, &ds2, &ds3, &ds4;
234
+ %end;
235
+
236
+ %mend mp_storediffs;
237
+ /** @endcond */
package/package.json CHANGED
@@ -38,5 +38,5 @@
38
38
  "dependencies": {
39
39
  "ts-loader": "^9.2.6"
40
40
  },
41
- "version": "2.58.3"
41
+ "version": "2.59.0"
42
42
  }