Type : CREATION_INTERNE
La macro procesa cadenas de caracteres proporcionadas como parámetros. No lee ni escribe datos SAS tradicionales o externos.
| 1 | %macro mf_wordsInStr1andStr2( |
| 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; |
| 1 | %IF %LENGTH(&str1)=0 or %LENGTH(&str2)=0 %THEN %DO; |
| 2 | %put base string (str1)= &str1; |
| 3 | %put compare string (str2) = &str2; |
| 4 | %return; |
| 5 | %END; |
| 1 | %let count_base=%sysfunc(countw(&Str2)); |
| 2 | %let count_extr=%sysfunc(countw(&Str1)); |
| 3 |
| 1 | %DO i=1 %to &count_extr; |
| 2 | %let extr_word=%scan(&Str1,&i,%str( )); |
| 3 | %let match=0; |
| 4 | %DO i2=1 %to &count_base; |
| 5 | %let base_word=%scan(&Str2,&i2,%str( )); |
| 6 | %IF &extr_word=&base_word %THEN %let match=1; |
| 7 | %END; |
| 8 | %IF &match=1 %THEN %let outvar=&outvar &extr_word; |
| 9 | %END; |
| 1 | &outvar |
| 2 | |
| 3 | %mend mf_wordsInStr1andStr2; |