%macro addsfxs(varlist,sfxlist); %*--Takes a list of variables and a list of suffixes to be appended to each name in the list. Example: varlist = a b c sfxlist=_1990 _2000 will return: a_1990 a_2000 b_1990 b_2000 c_1990 c_2000 Amending 4/23/2007 2:35PM to allow sfxlist to be a numeric interval such as "1-12" which gets expanded. So if varlist is Name Age Race and sfxlist is 1-4 then it generates: Name1 Name2 Name3 Name4 Age1 Age2 Age3 Age4 Race1 Race2 Race3 Race4. --; %local xL i j sfx var sfxnums sfxstart sfxend; %*--use the xpndlst macro to expand varlist in case it contains any shortened forms such as x1-x5 or name--zip --; %let xL=%xpndlst(&varlist); %*<---invokes our xpndlst utility macro that will look for simple numeric-suffix var lists and expanc them, i.e. x1-x5 converts to x1 x2 x3 x4 x5 --; %if %index(%superq(sfxlist),%str(-)) %then %do; %*---if we find a dash then we assume we have a numeric interval rather than a list of suffixes. E.g. 1-5 --; %let sfxnums=1; %*---logical flag used to test this condition below---; %let sfxstart=%scan(&sfxlist,1,%str(-)); %let sfxend=%scan(&sfxlist,2,%str(-)); %end; %else %do; %let sfxstart=%str(); %let sfxnums=0; %end; %let i=1; %let var=%scan(&xL,1); %loopI: %*--generate inner loop over the suffixes-; %let j=1; %if &sfxnums %then %let sfx=&sfxstart; %else %let sfx=%scan(&sfxlist,1); %loopJ: &var&sfx %if &sfxnums %then %do; %let sfx=%eval(&sfx+1); %if &sfx le &sfxend %then %goto loopj; %end; %else %do; %let j=%eval(&j+1); %let sfx=%scan(&sfxlist,&j); %if %bquote(&sfx) ne %str() %then %goto loopJ; %end; %let i=%eval(&i + 1); %let var=%scan(&xL,&i); %if %bquote(&var) ne %str() %then %goto loopI; %mend addsfxs;