Type : CREATION_INTERNE
La macro no lee ninguna fuente de datos. Opera sobre una lista de cadenas de caracteres proporcionada como parámetro durante su llamada.
| 1 | /*<pre><b> |
| 2 | / Program : editlist.sas |
| 3 | / Version : 1.0 |
| 4 | / Author : Roland Rashleigh-Berry |
| 5 | / Date : 01-Nov-2012 |
| 6 | / Purpose : Function-style macro to allow you to edit a list of space |
| 7 | / delimited items. |
| 8 | / SubMacros : none |
| 9 | / Notes : This macro is for tasks like generating rename statements where a |
| 10 | / repeat of items in a list is required (see usage notes). The edit |
| 11 | / string must be enclosed in single quotes. Elements of the list |
| 12 | / are written to the macro variable "item" which can be referenced |
| 13 | / in the edit string. If semicolons form part of the edit string |
| 14 | / then for certain uses these can be protected using %nrstr(). |
| 15 | / |
| 16 | / If used in sas code you might need to %unquote() the final string. |
| 17 | / |
| 18 | / This macro is essentially the same as the %doallitem macro but |
| 19 | / giving a different usage emphasis and with no submacros. |
| 20 | / |
| 21 | / Usage : %put >>> %editlist(aa bb cc dd,'&item=mr_&item'); |
| 22 | / %put >>> %editlist(xx_aa xx_bb xx_cc, |
| 23 | / '&item=%substr(&item,4)'); |
| 24 | / %put >>> %editlist(xx_aa xx_bb xx_cc, |
| 25 | / '%substr(&item,4)=&item%nrbquote(;)'); |
| 26 | / |
| 27 | / (will write to log:) |
| 28 | / >>> aa=mr_aa bb=mr_bb cc=mr_cc dd=mr_dd |
| 29 | / >>> xx_aa=aa xx_bb=bb xx_cc=cc |
| 30 | / >>> aa=xx_aa; bb=xx_bb; cc=xx_cc; |
| 31 | /=============================================================================== |
| 32 | / PARAMETERS: |
| 33 | /-------name------- -------------------------description------------------------ |
| 34 | / list (pos) List of space delimited items |
| 35 | / editstr (pos) Edit string (in single quotes) |
| 36 | /=============================================================================== |
| 37 | / AMENDMENT HISTORY: |
| 38 | / init --date-- mod-id ----------------------description------------------------ |
| 39 | / rrb 31Oct12 New (v1.0) |
| 40 | /=============================================================================== |
| 41 | / This is public domain software. No guarantee as to suitability or accuracy is |
| 42 | / given or implied. User uses this code entirely at their own risk. |
| 43 | /=============================================================================*/ |
| 44 | |
| 45 | %put MACRO CALLED: editlist v1.0; |
| 46 | |
| 47 | %macro editlist(list,editstr); |
| 48 | %local i item; |
| 49 | %let i=1; |
| 50 | %let item=%scan(&list,&i,%str( )); |
| 51 | %DO %while(%LENGTH(&item)); |
| 52 | %sysfunc(dequote(&editstr)) |
| 53 | %let i=%eval(&i + 1); |
| 54 | %let item=%scan(&list,&i,%str( )); |
| 55 | %END; |
| 56 | %mend editlist; |