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