sas语句将数值型变量和字符型变量分别重命名
%macro rename(datain=);
/*abtain the name and type of variables in dataset*/
proc contents data=&datain out=need(keep=name type) noprint;
run;
/*change the name into rename*/
data namelist;
set need;
if type=1 then name = compress(name||'='||cats("N_",name));
else name = compress(name||'='||cats("C_",name));
run;
/*create a macro variable--rename*/
proc sql nonprint;
select name into :rename separated by ' '
from namelist
quit;
/*rename the data*/
data a;
set &datain(rename=(&rename.));
run;
/*print the rename data*/
proc print data=a;
run;
%mend rename;
options mprint;
%rename(datain=sashelp.class);