|
> This might be simple but I'm trying to rename variables in a dataset
> dynamically.
>
> Conditions:
>
> 1. I only want to rename the variables that begin with an 'i'
> or an 'e' and
> rename those variables to i1, i2, i3, etc. and e1, e2, e3,
> etc respectively.
> 2. I will not know the number of variables in each set.
> 3. I do not want to hard code the old variables names.
> 4. I need it to be done dynamically.
I just tested this code, which only deals with "i" variables:
data work.test;
ivar1='This is ivar1';
ivar2='This is ivar2';
run;
proc datasets library=work memtype=data nolist;
contents data=test out=work.contents;
run;
quit;
data _null_;
set work.contents(keep=name) end=eof;
if _N_=1 then do;
call execute('data work.renamed;');
call execute('set work.test;');
end;
if upcase(name) eq: 'I' then do;
icounter+1;
call execute('rename '||trim(name)||'=i'
||trim(left(put(icounter,5.)))||';');
end;
if eof then call execute('run;');
run;
|