Type : CREATION_INTERNE
Esta macro no manipula conjuntos de datos. Opera sobre una cadena de caracteres pasada como parámetro para transformarla.
| 1 | /* |
| 2 | / Program : commaparms.sas |
| 3 | / Version : 1.0 |
| 4 | / Author : Roland Rashleigh-Berry |
| 5 | / Date : 10-Jun-2014 |
| 6 | / Purpose : Function-style macro to add back commas between macro parameters |
| 7 | / where these have been deliberately omitted in a string. |
| 8 | / SubMacros : none |
| 9 | / Notes : The result will be returned macro UNQUOTED so that equals signs |
| 10 | / are not macro quoted. |
| 11 | / |
| 12 | / Where a controlling macro allows the user to run other macros and |
| 13 | / supply parameters values then it is common practice to not use |
| 14 | / commas to separate the parameter values and to add these |
| 15 | / programatically when the called macro is invoked. This is done to |
| 16 | / avoid having to macro quote the whole string due to the presence |
| 17 | / of commas. This macro adds back the commas to the parameter list |
| 18 | / that are needed when the macro is called. |
| 19 | / |
| 20 | / The macro removes spaces either side of the equals sign and |
| 21 | / precedes the parameter name with a comma (removing the very first |
| 22 | / comma). |
| 23 | / |
| 24 | / Enclose the string for conversion inside %nrbquote() when calling |
| 25 | / this macro otherwise the first parameter name in the string will |
| 26 | / be interpreted as a macro parameter of the %commaparms macro. |
| 27 | / |
| 28 | / Usage : %let params=%commaparms(%nrbquote(&str)); |
| 29 | /=============================================================================== |
| 30 | / PARAMETERS: |
| 31 | /-------name------- -------------------------description------------------------ |
| 32 | / str (pos) String |
| 33 | /=============================================================================== |
| 34 | / AMENDMENT HISTORY: |
| 35 | / init --date-- mod-id ----------------------description------------------------ |
| 36 | / rrb 25Mar13 New (v1.0) |
| 37 | / rrb 10Jun14 Header tidy (v1.0) |
| 38 | /=============================================================================== |
| 39 | / This is public domain software. No guarantee as to suitability or accuracy is |
| 40 | / given or implied. User uses this code entirely at their own risk. |
| 41 | /=============================================================================*/ |
| 42 | |
| 43 | %put MACRO CALLED: commaparms v1.0; |
| 44 | |
| 45 | %macro commaparms(str); |
| 46 | %unquote(%qsubstr(%qsysfunc(prxchange(%nrbquote(s·\s*(\w+)\s*=\s*·,\1=·),-1, |
| 47 | %nrbquote(&str))),2)) |
| 48 | %mend commaparms; |