SAS 对数据集所有字段rename

 
 
%macro rnm(data=,out=);

proc contents data=&data

out=t1(keep=varnum name)
     noprint;
run;

proc sql noprint;
select  name
     into :classname separated by' '
     from t1
     order by varnum;
quit;

%put &classname;

data &out;
set &data;
%let i=1;
%do %until (%scan(&classname.,&i.," ")=);
	%let yn=%sysfunc(compress(%scan("&classname",&i," ")));
	
	rename &yn=C&i;
	%let i=%eval(&i.+1);

%end;

	proc datasets nolist;
	delete t1;
	run;
%mend;

/*调用*/

%rnm(data=test1,out=test2);

/*去除所有label*/

proc datasets lib=output noprint;
        attrib _all_ label='';
run;

  



  适用于:数据集字段需要批处理,且字段名称无规律,统一rename后方便后续操作。

上一篇:Juit和Mock


下一篇:new className() new出来的深意