分享一个简单的例子。如何批量给某些变量加些前缀或后缀
以sashelp.class 数据集为例。
http://blog.sina.com.cn/s/blog_41889b90010153bh.html
- ************************;
- ***macro definition;
- ************************;
- %macro renamevar(dslib,dsname,prefix,suffix,fromnum,tonum) ;
- ods listing close;
- ods trace on;
- ods output variables=varlist ;
- proc contents data=&dslib..&dsname;
- run;
- ods trace off;
- ods listing;
- proc sql;
- select cats(variable,"=","&prefix._",variable,"_&suffix")
- into :renamelist separated by " "
- from varlist
- where num between &fromnum and &tonum;
- quit;
- *********************************************************************;
- *** thanks for Malcolm's suggestion; proc datasets is more efficient.
- ***********************************************************************;
- proc datasets lib=&dslib ;
- modify &dsname;
- rename &renamelist;
- run;
- %mend renamevar;
- ******************;
- *** do it;
- *****************;
- %renamevar(sashelp,class,pre,suf,3,5);



雷达卡







京公网安备 11010802022788号







