@sasjs/core 4.67.3 → 4.68.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.
@@ -130,10 +130,10 @@ data _null_;
130
130
  * there is not much point importing a short length numeric like this,
131
131
  * eg with best4., as the resulting variable will still be stored as
132
132
  * length 8. We need a length or format statement to ensure variable
133
- * is creatd with the smaller length...
133
+ * is created with the smaller length...
134
134
  **/
135
135
  else if vlen<8 then header=cats(varnm,':best',vlen,'.');
136
- else header=cats(varnm,':best.');
136
+ else header=cats(varnm,':best32.');
137
137
  end;
138
138
  %end;
139
139
  %else %do;
@@ -17,7 +17,7 @@
17
17
  @li mf_getattrn.sas
18
18
  @li mf_getuniquename.sas
19
19
  @li mf_getvarlist.sas
20
- @li mp_md5.sas
20
+ @li mp_rowhash.sas
21
21
 
22
22
  <h4> Related Files </h4>
23
23
  @li mp_hashdataset.test.sas
@@ -46,8 +46,7 @@
46
46
 
47
47
  %local keyvar /* roll up the md5 */
48
48
  prevkeyvar /* retain prev record md5 */
49
- lastvar /* last var in input ds */
50
- cvars nvars;
49
+ lastvar /* last var in input ds */;
51
50
 
52
51
  %if not(%eval(%unquote(&iftrue))) %then %return;
53
52
 
@@ -79,10 +78,11 @@
79
78
  retain &prevkeyvar;
80
79
  if _n_=1 then &prevkeyvar=put(md5("&salt"),$hex32.);
81
80
  set &libds end=&lastvar;
82
- /* hash should include previous row */
83
- &keyvar=%mp_md5(
84
- cvars=%mf_getvarlist(&libds,typefilter=C) &prevkeyvar,
85
- nvars=%mf_getvarlist(&libds,typefilter=N)
81
+ /* hash should include previous row - listed first so it is hashed first */
82
+ %mp_rowhash(
83
+ md5_col=&keyvar
84
+ ,cvars=&prevkeyvar %mf_getvarlist(&libds,typefilter=C)
85
+ ,nvars=%mf_getvarlist(&libds,typefilter=N)
86
86
  );
87
87
  &prevkeyvar=&keyvar;
88
88
  if &lastvar then output;
@@ -45,7 +45,7 @@
45
45
  @li mp_aligndecimal.sas
46
46
  @li mp_cntlout.sas
47
47
  @li mp_lockanytable.sas
48
- @li mp_md5.sas
48
+ @li mp_rowhash.sas
49
49
  @li mp_storediffs.sas
50
50
 
51
51
  <h4> Related Macros </h4>
@@ -174,14 +174,19 @@ select distinct
174
174
  %let nvars=FMTROW MIN MAX DEFAULT LENGTH FUZZ MULT NOEDIT;
175
175
  data &base_fmts/note2err;
176
176
  set &base_fmts;
177
- fmthash=%mp_md5(cvars=&cvars, nvars=&nvars);
177
+ length fmthash $32;
178
+ %mp_rowhash(
179
+ md5_col=fmthash
180
+ ,cvars=&cvars
181
+ ,nvars=&nvars
182
+ )
178
183
  run;
179
184
 
180
185
  /**
181
186
  * Ensure input table and base_formats have consistent lengths and types
182
187
  */
183
188
  data &inlibds/nonote2err;
184
- length &delete_col $3 FMTROW 8 start end label $32767;
189
+ length &delete_col $3 FMTROW 8 start end label $32767 fmthash $32;
185
190
  if 0 then set &base_fmts;
186
191
  set &libds;
187
192
  by type fmtname notsorted;
@@ -203,7 +208,11 @@ data &inlibds/nonote2err;
203
208
  %mp_aligndecimal(end,width=16)
204
209
  end;
205
210
 
206
- fmthash=%mp_md5(cvars=&cvars, nvars=&nvars);
211
+ %mp_rowhash(
212
+ md5_col=fmthash
213
+ ,cvars=&cvars
214
+ ,nvars=&nvars
215
+ )
207
216
  run;
208
217
 
209
218
  /**
package/base/mp_md5.sas CHANGED
@@ -28,11 +28,16 @@
28
28
  @li Global option: `options dsoptions=nonote2err;`
29
29
  @li Data step option: `data YOURLIB.YOURDATASET /nonote2err;`
30
30
 
31
+ For very wide tables (hundreds or thousands of columns) consider using
32
+ `mp_rowhash.sas`, which builds the same type of row hash iteratively and
33
+ avoids creating a single, very long concatenated SAS expression.
34
+
31
35
  @param [in] cvars= () Space seperated list of character variables
32
36
  @param [in] nvars= () Space seperated list of numeric variables
33
37
 
34
38
  <h4> Related Programs </h4>
35
39
  @li mp_init.sas
40
+ @li mp_rowhash.sas
36
41
 
37
42
  @version 9.2
38
43
  @author Allan Bowe
@@ -0,0 +1,90 @@
1
+ /**
2
+ @file
3
+ @brief Iterative row-level MD5 hash generator
4
+ @details Generates DATA step statements that compute a deterministic,
5
+ row-level MD5 hash using a Merkle-style construction. Each variable is
6
+ hashed independently and the resulting raw 16-byte digests are combined
7
+ iteratively. This avoids concatenating the per-variable hex digests into a
8
+ single SAS character expression, which overflows when datasets contain many
9
+ variables.
10
+
11
+ Temporary variables use five leading underscores.
12
+
13
+ This macro is called from inside a DATA step. The caller is responsible
14
+ for declaring the output hash column if it does not already exist on the
15
+ input dataset.
16
+
17
+ Variables are hashed in the order supplied. If a particular variable
18
+ needs to influence the hash first (for example the previous row hash in
19
+ `mp_hashdataset`, or business dates in Data Controller's bitemporal
20
+ loader) simply list it first in `cvars` or `nvars`.
21
+
22
+ @param [in] md5_col= Name of the output hash column.
23
+ @param [in] cvars= Space separated list of character variables to hash.
24
+ @param [in] nvars= Space separated list of numeric variables to hash.
25
+
26
+ @version 9.3M5
27
+ @author Allan Bowe
28
+ **/
29
+
30
+ %macro mp_rowhash(
31
+ md5_col=
32
+ ,cvars=
33
+ ,nvars=
34
+ );
35
+
36
+ /* DATA step temp variables use five leading underscores. The names
37
+ are generated at macro invocation to avoid clashing with data columns. */
38
+ %local state digest pair numtext normal i chars nums;
39
+ %let state=%mf_getuniquename(prefix=_____state_);
40
+ %let digest=%mf_getuniquename(prefix=_____digest_);
41
+ %let pair=%mf_getuniquename(prefix=_____pair_);
42
+ %let numtext=%mf_getuniquename(prefix=_____numtext_);
43
+ %let normal=%mf_getuniquename(prefix=_____normal_);
44
+ %let i=%mf_getuniquename(prefix=_____i_);
45
+ %let chars=%mf_getuniquename(prefix=_____chars_);
46
+ %let nums=%mf_getuniquename(prefix=_____nums_);
47
+
48
+ length &state $16
49
+ &digest $16
50
+ &pair $32
51
+ &numtext $64
52
+ &normal &i 8;
53
+ if _n_=1 then call missing(&state,&digest,&pair,&numtext,&normal,&i);
54
+ drop &state &digest &pair &numtext &normal &i;
55
+
56
+ /* Versioned seed prevents confusion with other hashing schemes. */
57
+ &state = md5('DC HASH v2');
58
+
59
+ %if %length(&cvars)>0 %then %do;
60
+ array &chars{*} $ &cvars;
61
+ do &i = 1 to dim(&chars);
62
+ /* Leading blanks are retained. */
63
+ &digest = md5(trimn(&chars[&i]));
64
+ substr(&pair, 1, 16) = &state;
65
+ substr(&pair, 17, 16) = &digest;
66
+ &state = md5(&pair);
67
+ end;
68
+ %end;
69
+
70
+ %if %length(&nvars)>0 %then %do;
71
+ array &nums{*} &nvars;
72
+ do &i = 1 to dim(&nums);
73
+ /*
74
+ multiply-by-one for consistent cross-system precision.
75
+ Ignore null to protect SAS special missing values.
76
+ Cannot use IFN() as it evaluates both sides
77
+ */
78
+ if missing(&nums[&i]) then &normal = &nums[&i];
79
+ else &normal = &nums[&i] * 1;
80
+ &numtext = put(&normal, binary64.);
81
+ &digest = md5(trim(&numtext));
82
+ substr(&pair, 1, 16) = &state;
83
+ substr(&pair, 17, 16) = &digest;
84
+ &state = md5(&pair);
85
+ end;
86
+ %end;
87
+
88
+ &md5_col = put(&state, $hex32.);
89
+
90
+ %mend mp_rowhash;
package/package.json CHANGED
@@ -35,5 +35,5 @@
35
35
  "maintainers": [
36
36
  "https://sasapps.io"
37
37
  ],
38
- "version": "4.67.3"
38
+ "version": "4.68.0"
39
39
  }