I am sorry if this is the wrong forum.
I've modified the code from one of the SAS-papers: Paper 118-28, "Renaming All Variables in a SAS® Data Set Using the Information from PROC SQL's Dictionary Tables", Prasad Ravi ,Household Credit Services, Beaverton, OR
to look like the following. I am having trouble with the renaming part (bolded). Its something to do with the %if statements i think.
Any thoughts?
thanks,
Sachin
*test data;
Data one;
U=1;
V=2;
_X=3;
Y=4;
Z=5;
Run;
/* Running the renaming macro */
options macrogen mprint mlogic;
/* Running the renaming macro */
%macro rename(lib,dsn);
/*create a temporary fily by appending name with '2'*/
data &lib..&dsn.2;
set &lib..&dsn;
run;
/*get the number of variables and the variable names*/
proc sql noprint;
select nvar into :num_vars
from dictionary.tables
where libname="&LIB" and
memname="&DSN.2";
select distinct(name) into :var1-
:var%TRIM(%LEFT(&num_vars))
from dictionary.columns
where libname="&LIB" and
memname="&DSN.2";
quit;
run;
/*reaname the variable*/
proc datasets library=&LIB;
modify &DSN.2;
rename
%do i=1 %to &num_vars;
%if &i=1 %then %do;
&&var&i=x;
%end;
%else %do;
&&var&i=y&i;
%end;
%end;
quit;
run;
%mend rename;
%rename(WORK,ONE);
... View more