I got a lot of dataset which each variable start by a letter. By example : Dataset 1: Avar1 Avar2 Avar3 ..... Avark Dataset2: Bvar1 Bvar2 Bvar3 .... Bvarn And I would like them to become : Dataset 1: Vvar Vvar2 Vvar3 ..... Vvark Dataset2: Vvar1 Vvar2 Vvar3 .... Vvarn I found a macro who could do the job for only one dataset : ` %macro replaceprefix(lib,dsn,start,end,oldprefix,newprefix);
proc contents data=&lib..&dsn. ;
title 'before renaming';
run;
data temp;
set &lib..&dsn.;
run;
%LET ds=%SYSFUNC(OPEN(temp,i));
%let ol=%length(&oldprefix.);
%do i=&start %to &end;
%let dsvn&i=%SYSFUNC(VARNAME(&ds,&i));
%let l=%length(&&dsvn&i);
%let vn&i=&newprefix.%SUBSTR(&&dsvn&i,&ol+1,%EVAL(&l-&ol));
%end;
data &lib..&dsn.;
set temp;
%do i=&start %to &end;
&&vn&i=&&dsvn&i;
drop &&dsvn&i;
%end;
%let rc=%SYSFUNC(CLOSE(&ds));
proc contents data=&lib..&dsn.;
title 'Replacing Prefix on Selected variables ';
run; %mend replaceprefix; After, I tried to automate this macro for all my dataset. I created the following Macro: %macro test(end,ele,letter);
%do k=1 %TO &end;
%Let i= %scan(&ele,&k);
%Let j=%scan(&letter,&k);
%let nvar= %sysfunc(attrnd(&i,nvars));
%replaceprefix(WORK,&i,1,&nvar,&j,v);
data &i; set &i; van=&k; run; %end;
%mend ; I received the following error code : ERROR: The ATTRND function referenced in the %SYSFUNC or %QSYSFUNC macro function is not found. ERROR: %EVAL function has no expression to evaluate, or %IF statement has no condition. ERROR: The %TO value of the %DO M loop is invalid. ERROR: The macro REPLACEPREFIX will stop executing. ERROR: The ATTRND function referenced in the %SYSFUNC or %QSYSFUNC macro function is not found. Any idea why ? Thank's everyone.
... View more