Hello SAS community! I created a macro to help me rename variables by groups. The only problem is sometimes it works and sometimes it doesn't. The main issue is the first CALL SYMPUT. The creation of the "cw" variable always works, but the CALL SYMPUT doesn't always pull in the value. Instead when I run "%put &c." I just get "&c" in the log. Because the macro is never created, I get the following error: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &c. ERROR: The %TO value of the %DO I loop is invalid. ERROR: The macro RENAME will stop executing. I have no clue what the root of the issue is. I'll tweak the code and it'll run fine. Then to test the new code I will close out SAS and reopen the program and run the same code that just worked. I always get the same error. Hopefully, this is a simple problem! The code below has run successfully and unsuccessfully with no changes. Thanks for all of your help! %macro rename(oldvarlist,suffix); length prefix var newvar $ 32.; cw = countw("&oldvarlist",' '); put cw = ; call symputx('c',cw); %put &c.; %let k=1; %let old = %scan(&oldvarlist, &k); %do i = 1 %to &c.; l = anylower("&old"); u = anyupper("&old"); var = left(substr("&old",(l-1))); prefix = left(substr("&old",u,l-2)); newvar = strip(catx("_",prefix,"&suffix",var)); call symput("&suffix.&i.",newvar); %put &&&suffix.&i.; rename &old = &&&suffix.&i.; %let k = %eval(&k + 1); %let old = %scan(&oldvarlist, &k); %end; drop cw l u var prefix newvar; %mend; options mprint symbolgen; data _null_; %rename(PAForms PALevelChange PAGrad PAMilestone PAFuf PABenefits, admn); run;
... View more