I’m working on a macro that uses DATA steps, PROC TRANSPOSE and PROC SQL. As a consequence of using PROC SQL, I need the same variable list both with and without commas.
My original solution was to use %str() and then COMPRESS() inside the macro to get rid of the embedded commas.
I would prefer to have the variable list without commas, and to add a second series of variables in some cases.
The code below works, but I’m sure there has to be a better method. Also, is there a way to test if &addmore is null directly?
Thanks for any help you can give me.
WendyT
%macro addcommas(somevars,addmore);
%let nullval = ;
%if &addmore ne &nullval %then
%let commavalue=%SYSFUNC(TRANSLATE(&somevars, ', ', ' ')),%SYSFUNC(TRANSLATE(&addmore, ', ', ' '));
%else %let commavalue=%SYSFUNC(TRANSLATE(&somevars, ', ', ' ')) ;
%put &commavalue;
%mend;
%addcommas(a b c, d e f) ;
a,b,c,d,e,f
%addcommas(a b c, ) ;
a,b,c