There is several things wrong here. Firstly you don't need macro code for this, and using it is the reason you are having problems. Use Base SAS which is the programming language. Second off, you are mixing macro and datastep. You need to understand that Macro is not the executable code, it just generates some text which then goes into the compiler - hence why you should use it sparingly and only for specific circumstances, not for every bit of code you do.
This:
%if _n_ = &ID. %then;
_n_ is a datastep automatic variable, it is not available to the macro processor. This will not work.
This:
column99 = &CalcCost;
Calcost is not defined in the code you provide nor is &nobs
This:
%do ID=1 %to &nobs;
There is no associated %end stament with this.
This:
%global chargerate Amount;
Its really a bad idea to create global macro variables from within a macro, you could alter something at higher levels.
At the end of the day, this code could be a simple datastep - provide test data in the form of a datastep and we can provide working code.
... View more