Loading...
Searching...
No Matches
mf_wordsinstr1butnotstr2.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Returns words that are in string 1 but not in string 2
4 @details Compares two space separated strings and returns the words that are
5 in the first but not in the second.
6
7 Note - case sensitive!
8
9 If str1 is empty, nothing is returned. If str2 is empty, all the words in
10 str1 are returned.
11
12 Usage:
13
14 %let x= %mf_wordsinstr1butnotstr2(
15 Str1=blah sss blaaah brah bram boo
16 ,Str2= blah blaaah brah ssss
17 );
18
19 returns:
20 > sss bram boo
21
22 @param [in] str1= () String containing words to extract
23 @param [in] str2= () Used to compare with the extract string
24
25 @version 9.2
26 @author Allan Bowe
27
28**/
29
30%macro mf_wordsinstr1butnotstr2(
31 Str1= /* string containing words to extract */
32 ,Str2= /* used to compare with the extract string */
33)/*/STORE SOURCE*/;
34
35%local count_extr i extr_word outvar;
36%if %length(&str1)=0 %then %do;
37 %put &sysmacroname: str1 is empty, nothing to compare;
38 %return;
39%end;
40%let count_extr=%sysfunc(countw(&Str1));
41
42%do i=1 %to &count_extr;
43 %let extr_word=%scan(&Str1,&i,%str( ));
44 %if %sysfunc(indexw(%superq(str2),%superq(extr_word)))=0 %then
45 %let outvar=&outvar &extr_word;
46%end;
47/* send out the result without any surrounding whitespace */
48%do;&outvar%end;
49%mend mf_wordsinstr1butnotstr2;