@sasjs/core 4.67.3 → 4.68.1
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/mf_wordsinstr1andstr2.sas +12 -17
- package/base/mf_wordsinstr1butnotstr2.sas +13 -18
- package/base/mp_ds2csv.sas +2 -2
- package/base/mp_hashdataset.sas +7 -7
- package/base/mp_loadformat.sas +13 -4
- package/base/mp_md5.sas +5 -0
- package/base/mp_rowhash.sas +90 -0
- package/package.json +1 -1
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
@brief Returns words that are in both string 1 and string 2
|
|
4
4
|
@details Compares two space separated strings and returns the words that are
|
|
5
5
|
in both.
|
|
6
|
+
|
|
7
|
+
If either string is empty, nothing is returned.
|
|
8
|
+
|
|
6
9
|
Usage:
|
|
7
10
|
|
|
8
|
-
%put %
|
|
11
|
+
%put %mf_wordsinstr1andstr2(
|
|
9
12
|
Str1=blah sss blaaah brah bram boo
|
|
10
13
|
,Str2= blah blaaah brah ssss
|
|
11
14
|
);
|
|
@@ -23,31 +26,23 @@
|
|
|
23
26
|
|
|
24
27
|
**/
|
|
25
28
|
|
|
26
|
-
%macro
|
|
29
|
+
%macro mf_wordsinstr1andstr2(
|
|
27
30
|
Str1= /* string containing words to extract */
|
|
28
31
|
,Str2= /* used to compare with the extract string */
|
|
29
32
|
)/*/STORE SOURCE*/;
|
|
30
33
|
|
|
31
|
-
%local
|
|
34
|
+
%local count_extr i extr_word outvar;
|
|
32
35
|
%if %length(&str1)=0 or %length(&str2)=0 %then %do;
|
|
33
|
-
%put
|
|
34
|
-
%put compare string (str2) = &str2;
|
|
36
|
+
%put &sysmacroname: empty input string, nothing to compare;
|
|
35
37
|
%return;
|
|
36
38
|
%end;
|
|
37
|
-
%let count_base=%sysfunc(countw(&Str2));
|
|
38
39
|
%let count_extr=%sysfunc(countw(&Str1));
|
|
39
40
|
|
|
40
41
|
%do i=1 %to &count_extr;
|
|
41
42
|
%let extr_word=%scan(&Str1,&i,%str( ));
|
|
42
|
-
%
|
|
43
|
-
|
|
44
|
-
%let base_word=%scan(&Str2,&i2,%str( ));
|
|
45
|
-
%if &extr_word=&base_word %then %let match=1;
|
|
46
|
-
%end;
|
|
47
|
-
%if &match=1 %then %let outvar=&outvar &extr_word;
|
|
43
|
+
%if %sysfunc(indexw(%superq(str2),%superq(extr_word)))>0 %then
|
|
44
|
+
%let outvar=&outvar &extr_word;
|
|
48
45
|
%end;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
%mend mf_wordsInStr1andStr2;
|
|
53
|
-
|
|
46
|
+
/* send out the result without any surrounding whitespace */
|
|
47
|
+
%do;&outvar%end;
|
|
48
|
+
%mend mf_wordsinstr1andstr2;
|
|
@@ -6,9 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
Note - case sensitive!
|
|
8
8
|
|
|
9
|
+
If str1 is empty, nothing is returned. If str2 is empty, all the words in
|
|
10
|
+
str1 are returned.
|
|
11
|
+
|
|
9
12
|
Usage:
|
|
10
13
|
|
|
11
|
-
%let x= %
|
|
14
|
+
%let x= %mf_wordsinstr1butnotstr2(
|
|
12
15
|
Str1=blah sss blaaah brah bram boo
|
|
13
16
|
,Str2= blah blaaah brah ssss
|
|
14
17
|
);
|
|
@@ -24,31 +27,23 @@
|
|
|
24
27
|
|
|
25
28
|
**/
|
|
26
29
|
|
|
27
|
-
%macro
|
|
30
|
+
%macro mf_wordsinstr1butnotstr2(
|
|
28
31
|
Str1= /* string containing words to extract */
|
|
29
32
|
,Str2= /* used to compare with the extract string */
|
|
30
33
|
)/*/STORE SOURCE*/;
|
|
31
34
|
|
|
32
|
-
%local
|
|
33
|
-
%if %length(&str1)=0
|
|
34
|
-
%put
|
|
35
|
-
%put compare string (str2) = &str2;
|
|
35
|
+
%local count_extr i extr_word outvar;
|
|
36
|
+
%if %length(&str1)=0 %then %do;
|
|
37
|
+
%put &sysmacroname: str1 is empty, nothing to compare;
|
|
36
38
|
%return;
|
|
37
39
|
%end;
|
|
38
|
-
%let count_base=%sysfunc(countw(&Str2));
|
|
39
40
|
%let count_extr=%sysfunc(countw(&Str1));
|
|
40
41
|
|
|
41
42
|
%do i=1 %to &count_extr;
|
|
42
43
|
%let extr_word=%scan(&Str1,&i,%str( ));
|
|
43
|
-
%
|
|
44
|
-
|
|
45
|
-
%let base_word=%scan(&Str2,&i2,%str( ));
|
|
46
|
-
%if &extr_word=&base_word %then %let match=1;
|
|
47
|
-
%end;
|
|
48
|
-
%if &match=0 %then %let outvar=&outvar &extr_word;
|
|
44
|
+
%if %sysfunc(indexw(%superq(str2),%superq(extr_word)))=0 %then
|
|
45
|
+
%let outvar=&outvar &extr_word;
|
|
49
46
|
%end;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
%mend mf_wordsInStr1ButNotStr2;
|
|
54
|
-
|
|
47
|
+
/* send out the result without any surrounding whitespace */
|
|
48
|
+
%do;&outvar%end;
|
|
49
|
+
%mend mf_wordsinstr1butnotstr2;
|
package/base/mp_ds2csv.sas
CHANGED
|
@@ -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
|
|
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,':
|
|
136
|
+
else header=cats(varnm,':best32.');
|
|
137
137
|
end;
|
|
138
138
|
%end;
|
|
139
139
|
%else %do;
|
package/base/mp_hashdataset.sas
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
@li mf_getattrn.sas
|
|
18
18
|
@li mf_getuniquename.sas
|
|
19
19
|
@li mf_getvarlist.sas
|
|
20
|
-
@li
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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;
|
package/base/mp_loadformat.sas
CHANGED
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
@li mp_aligndecimal.sas
|
|
46
46
|
@li mp_cntlout.sas
|
|
47
47
|
@li mp_lockanytable.sas
|
|
48
|
-
@li
|
|
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
|
|
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
|
-
|
|
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