Type : CREATION_INTERNE
The `%mf_wordsInStr1ButNotStr2` macro exclusively processes character strings passed to it as arguments (`Str1` and `Str2`). There is no direct access to existing SAS datasets (including SASHELP) or external files for its main operations. The 'data' processed are therefore textual values provided dynamically during the macro call, not requiring pre-existing external or internal data sources.
| 1 | %macro mf_wordsInStr1ButNotStr2( |
| 2 | Str1= /* string containing words to extract */ |
| 3 | ,Str2= /* used to compare with the extract string */ |
| 4 | )/*/STORE SOURCE*/; |
| 5 | |
| 6 | %local count_base count_extr i i2 extr_word base_word match outvar; |
| 7 | %IF %LENGTH(&str1)=0 or %LENGTH(&str2)=0 %THEN %DO; |
| 8 | %put base string (str1)= &str1; |
| 9 | %put compare string (str2) = &str2; |
| 10 | %return; |
| 11 | %END; |
| 12 | %let count_base=%sysfunc(countw(&Str2)); |
| 13 | %let count_extr=%sysfunc(countw(&Str1)); |
| 14 | |
| 15 | %DO i=1 %to &count_extr; |
| 16 | %let extr_word=%scan(&Str1,&i,%str( )); |
| 17 | %let match=0; |
| 18 | %DO i2=1 %to &count_base; |
| 19 | %let base_word=%scan(&Str2,&i2,%str( )); |
| 20 | %IF &extr_word=&base_word %THEN %let match=1; |
| 21 | %END; |
| 22 | %IF &match=0 %THEN %let outvar=&outvar &extr_word; |
| 23 | %END; |
| 24 | |
| 25 | &outvar |
| 26 | |
| 27 | %mend mf_wordsInStr1ButNotStr2; |