Type : CREATION_INTERNE
La macro opère sur une chaîne de caractères fournie comme paramètre `var`. Elle ne lit ni ne crée de jeux de données SAS externes ou internes. Les données sont transformées directement à partir de l'entrée de la macro.
| 1 | %macro parse |
| 2 | ( |
| 3 | var, /* input character var or string */ |
| 4 | with, /* characters to parse on */ |
| 5 | ACTION, /* action for each parsed word */ |
| 6 | nextword=nextword, /* variable to assign next word to */ |
| 7 | nwords=nwords /* the index of the word in the string */ |
| 8 | ); |
| 9 | |
| 10 | %* Parse "var" with "with". For each parsed word, DO "action".; |
| 11 | %* |
| 12 | %* |
| 13 | %* "VAR" is a SAS character variable or character string. |
| 14 | %* |
| 15 | %* "WITH" is a character or SET of characters that break "var" |
| 16 | %* into words or phrases (passed to the "scan" function). |
| 17 | %* |
| 18 | %* "ACTION" is an ACTION to take for each word or phrase. |
| 19 | %* |
| 20 | * I usually use "LINK label" as the ACTION, and have the subroutine |
| 21 | * at "label" issue a "return" to get back here. |
| 22 | * IF the ACTION is invoking a macro, use the "%nrquote" function. |
| 23 | %* |
| 24 | * |
| 25 | * barry grau |
| 26 | * u42054 @uicvm.bitnet |
| 27 | * u42054 @uicvm.uic.edu |
| 28 | * fall 1987 |
| 29 | %* |
| 30 | ; |
| 31 | |
| 32 | LENGTH &nextword $ 80; |
| 33 | |
| 34 | string=%quote(&var); |
| 35 | &nwords=0; |
| 36 | |
| 37 | * for each parsed "word", set &nextword="word" and do the "action".; |
| 38 | DO until (&nextword=' '); |
| 39 | &nwords=&nwords+1; |
| 40 | &nextword=scan(string,&nwords,&with); |
| 41 | IF ^(&nextword=' ') |
| 42 | THEN DO; |
| 43 | %quote(&ACTION); |
| 44 | END; |
| 45 | END; |
| 46 | |
| 47 | %mend; |