Type : CREATION_INTERNE
Das Makro `%mf_wordsInStr1ButNotStr2` verarbeitet ausschließlich Zeichenketten, die ihm als Argumente (`Str1` und `Str2`) übergeben werden. Es gibt keinen direkten Zugriff auf vorhandene SAS-Datasets (einschließlich SASHELP) oder externe Dateien für seine Hauptoperationen. Die verarbeiteten 'Daten' sind somit Textwerte, die dynamisch beim Aufruf des Makros bereitgestellt werden und keine externen oder internen vordefinierten Datenquellen erfordern.
| 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; |