Hi all am trying to execute column rename for a large data set , am getting below error
all is i am trying to all column names in different variables, and trying to rename .
%macro rename;
proc sql noprint;
select count(*) into :n
from sashelp.vcolumn
where libname='WORK' and
memname='_VAR_OLD';
select distinct(name) into :var1-:var&n
from sashelp.vcolumn
where libname='WORK' and
memname='_VAR_OLD';
quit;
proc datasets libname='WORK' nolist;
modify _var_old;
rename
%do i=1 %to &n;
%if %index(%upcase(&except), %upcase(&&var&i)) eq 0 %then
%do;
&var&i=OLD_&var&i.
%end;
%end;
;
quit;
%mend rename;
NOTE: Line generated by the macro variable "N".
326 var 8
_
22
76
ERROR 22-322: Syntax error, expecting one of the following: ',', FROM, NOTRIM.
ERROR 76-322: Syntax error, statement will be ignored.
NOTE: Line generated by the invoked macro "RENAME".
326 proc datasets libname='WORK' nolist; modify _var_old;
_______ ______
1 22
200
NOTE: Enter RUN; to continue or QUIT; to end the procedure.
NOTE: Statements not processed because of errors noted above.
WARNING 1-322: Assuming the symbol LIB was misspelled as libname.
Apparent symbolic reference VAR1 not resolved.
NOTE 138-205: Line generated by the macro variable "I".
326 OLD_&var1
_
22
ERROR 22-322: Expecting a name.
Please post test data in the form of a datastep, and what the output should look like.
Also, we had more or less exactly the same question yesterday:
Indirect addressing of macro variables needs a double ampersand.
To get the contents of &var6 when &i=6, use &&var&i
Thanks for quick help, am trying to execute the below code , but still can't able to resolve the variable
%macro rename;
proc sql noprint;
select count(*) into :n
from sashelp.vcolumn
where libname='WORK' and
memname='_VAR_OLD';
select distinct(name) into :var1-:var&n
from sashelp.vcolumn
where libname='WORK' and
memname='_VAR_OLD';
quit;
proc datasets libname='WORK' nolist;
modify _var_old;
rename
%do i=1 %to &n;
%if %index(%upcase(&except), %upcase(&&var&i)) eq 0 %then
%do;
&&var&i=OLD_&&var&i.
%end;
%end;
;
quit;
%mend rename;
Can that macro, it's much easier in a simple data step with call execute:
data class;
set sashelp.class;
run;
data _null_;
set sashelp.vcolumn (where=(libname = "WORK" and memname = "CLASS")) end=eof;
if _n_ = 1 then call execute("proc datasets lib=WORK nolist;modify CLASS; rename");
call execute(' ' !! trim(name) !! '=old_' !! trim(name));
if eof then call execute(';quit;');
run;
You've got a few problems:
Please post test data in the form of a datastep, and what the output should look like.
Also, we had more or less exactly the same question yesterday:
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.