Rename all vars in a dataset using SASHELP

This post was kindly contributed by SAS & Statistics - go there to comment and to read the full post.

*Create a temporary dataset… DSN;
data dsn;
a=1;
b=2;
c=3;
d=4;
e=5;
f=6;
run;

%macro test(lib,dsn);

*/1)*/ data _null_;
&nbsp &nbsp &nbsp set sashelp.vtable(where=(libname=”&LIB” and memname=”&DSN”));
&nbsp &nbsp &nbsp call symput(‘nvars’,nvar);
run;

*/2)*/ data dsn;
&nbsp &nbsp &nbsp set sashelp.vcolumn(where=(libname=”&LIB” and memname=”&DSN”));
&nbsp &nbsp &nbsp call symput(cats(“var”,_n_),name);
run;

*/3)*/ proc datasets library=&LIB;
&nbsp &nbsp &nbsp modify &DSN;
&nbsp &nbsp &nbsp rename
&nbsp &nbsp &nbsp %do i = 1 %to &nvars;
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &&var&i=Rename_&&var&i.
&nbsp &nbsp &nbsp %end;
&nbsp &nbsp &nbsp ;
quit;
run;
%mend;

%test(WORK,DSN);

This post was kindly contributed by SAS & Statistics - go there to comment and to read the full post.