Type : CREATION_INTERNE
La macro `%mf_wordsInStr1ButNotStr2` procesa exclusivamente las cadenas de caracteres que se le pasan como argumentos (`Str1` y `Str2`). No hay acceso directo a conjuntos de datos SAS existentes (incluido SASHELP) o a archivos externos para sus operaciones principales. Por lo tanto, los 'datos' procesados son valores textuales proporcionados dinámicamente durante la llamada a la macro, sin requerir fuentes de datos externas o internas preexistentes.
| 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; |