Here's a macro I use for such things:
/*******************************************************************************
* Name: lisuffix (List Item Suffix) *
* Desc: Returns a list with the specified suffix appended to each item. *
* Type: Macro Function - List *
* Usage: %lisuffix ( list , suffix ) *
* Where: list is a space delimited list *
* suffix is any string of characters *
* Examples: *
* 1) %let fylist=1996 1997 1998; *
* %let newlist=%lisuffix(&fylist,%str(,)); *
* %put ===> newlist=&newlist; *
* ===> newlist=1996,1997,1998, *
* 2) %let datelist=01JAN1999 01FEB1999 01MAR1999; *
* %let newlist=%liprefix(&datelist,%bquote(')); *
* %let newlist=%lisuffix(%bquote(&newlist),%bquote('d)); *
* %put ===> newlist=&newlist; *
* ===> '01JAN1999'd '01FEB1999'd '01MAR1999'd *
* History: *
* 3/15/00 Walt Smith - development *
*******************************************************************************/
%macro lisuffix (_list,_suff) /
des = 'Fn: Suffix each item in list with string'
;
%local return i signal wrd delim;
%let delim=%str( );
%let i=0;
%let signal=CONTINUE;
%do %until(&signal=DONE);
%let i=%eval(&i +1);
%let wrd=%qscan(&_list,&i,%str(&delim));
%if %length(&wrd)=0 %then
%let signal=DONE;
%else
%let return = &return.%str(&wrd)%str(&_suff)%str(&delim);
%end;
%unquote(&return)
%mend;
You need to be aware of macro quoting - if what you want to append to each item in your original list contains anything that is meaningful in calling a macro (like = signs, commas, etc) then just quote the whole thing. In your case, as I read your question you want to add ', (n, mean, var)' to each of x1 x2 x3:
%let ind_variable = x1 x2 x3;
%let newstr = %lisuffix( &ind_variable, %bquote(, (n, mean, var)) );
%put newstr = "&newstr";
result:
newstr = "x1, (n, mean, var) x2, (n, mean, var) x3, (n, mean, var)"
ouch! I just previewed this post and they filter out all whitespace so the macro looks pretty ugly - sorry ...