%macro renamel(varlist,suffix,form=dsopt); %*--Renames a list of variables by appending a specified suffix to name of each variable in the specified input list. This macro invokes the xpndlst utility macro. This macro will generate a rename statement (if form=stmt specified) or sas dataset option (default) that will cause all variables appearing in varlist to be renamed by appending the value of the suffix parameter to its name. For example: varlist=pop hus, suffix=_1990, form=dsopt : The macro generates the code: rename=(pop=pop_1990 hus=hus_1990) --; %local xL i var; %if %upcase(%substr(&form,1,1))=S %then %let form=s; %else %let form=d; %if &form=d %then %do; rename=( %end; %else %str( rename ); %*--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 --; %let i=1; %let var=%scan(&xL,1); %loop: &var = &var&suffix %let i=%eval(&i + 1); %let var=%scan(&xL,&i); %if %bquote(&var) ne %str() %then %goto loop; %if &form=d %then %str ( ) ); %else %str( ; ); %*--end the dsopt or the rename stmt--; %mend renamel;