@sasjs/core 2.59.1 → 2.60.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/mf_dedup.sas +54 -0
- package/package.json +1 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief de-duplicates a macro string
|
|
4
|
+
@details Removes all duplicates from a string of words. A delimeter can be
|
|
5
|
+
chosen. Is inspired heavily by this excellent [macro](
|
|
6
|
+
https://github.com/scottbass/SAS/blob/master/Macro/dedup_mstring.sas) from
|
|
7
|
+
[Scott Base](https://www.linkedin.com/in/scottbass). Case sensitive.
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
|
|
11
|
+
%let str=One two one two and through and through;
|
|
12
|
+
%put %mf_dedup(&str);
|
|
13
|
+
%put %mf_dedup(&str,outdlm=%str(,));
|
|
14
|
+
|
|
15
|
+
Which returns:
|
|
16
|
+
|
|
17
|
+
> One two one and through
|
|
18
|
+
> One,two,one,and,through
|
|
19
|
+
|
|
20
|
+
@param [in] str String to be deduplicated
|
|
21
|
+
@param [in] indlm= ( ) Delimeter of the input string
|
|
22
|
+
@param [out] outdlm= ( ) Delimiter of the output string
|
|
23
|
+
|
|
24
|
+
<h4> Related Macros </h4>
|
|
25
|
+
@li mf_trimstr.sas
|
|
26
|
+
@li mf_wordsinstr1butnotstr2.sas
|
|
27
|
+
|
|
28
|
+
@version 9.2
|
|
29
|
+
@author Allan Bowe
|
|
30
|
+
**/
|
|
31
|
+
|
|
32
|
+
%macro mf_dedup(str
|
|
33
|
+
,indlm=%str( )
|
|
34
|
+
,outdlm=%str( )
|
|
35
|
+
)/*/STORE SOURCE*/;
|
|
36
|
+
|
|
37
|
+
%local num word i pos out;
|
|
38
|
+
|
|
39
|
+
%* loop over each token, searching the target for that token ;
|
|
40
|
+
%let num=%sysfunc(countc(%superq(str),%str(&indlm)));
|
|
41
|
+
%do i=1 %to %eval(&num+1);
|
|
42
|
+
%let word=%scan(%superq(str),&i,%str(&indlm));
|
|
43
|
+
%let pos=%sysfunc(indexw(&out,&word,%str(&outdlm)));
|
|
44
|
+
%if (&pos eq 0) %then %do;
|
|
45
|
+
%if (&i gt 1) %then %let out=&out%str(&outdlm);
|
|
46
|
+
%let out=&out&word;
|
|
47
|
+
%end;
|
|
48
|
+
%end;
|
|
49
|
+
|
|
50
|
+
%unquote(&out)
|
|
51
|
+
|
|
52
|
+
%mend mf_dedup;
|
|
53
|
+
|
|
54
|
+
|
package/package.json
CHANGED