Let's just look at your stated objective of creating a utility macro that will increment a given macro variable by one and ignore the irrelevant data step code as just part of your attempt to debig your problem. Here is your proposed macro definition
%macro incrementvar(vartoincrement);
%let vartoincrement = %eval(&vartoincrement. + 1);
%mend;
The %LET statement looks fine if you just wanted to increment a variable named VARTOINCREMENT. But if you are trying to create a macro takes as input the Name of a macro variable that you want to increment then you need to change this code becuase it is currently trying to add one to the NAME of the macro variable and store the result back into the macro variable that holds the input to the macro.
What you did was like this:
%let X=1;
%let NAME=X;
%let NAME = %EVAL(X + 1);
So first you are trying to add one to the string X, which won't work. To fix that we need to use the vlaue of macro variable whose name is the value of the macro variable NAME. To do that we need to use &&&NAME.
Then you are trying to store the result back into the variable NAME instead of into the variable X. To fix that we need to replace NAME with &NAME.
So now your macro looks like this:
%macro incrementvar(vartoincrement);
%let &vartoincrement = %eval(&&&vartoincrement. + 1);
%mend;
... View more