We have already shown you how to loop over months, https://communities.sas.com/t5/SAS-Programming/calculate-macro-variables-in-structure-YYMM/m-p/951717#M372005. Which makes me wonder why you didn't try that.
This looks like you want a moving average (or moving sum) of six months. If so, then you don't want macros at all, you want PROC EXPAND.
https://blogs.sas.com/content/iml/2016/01/27/moving-average-in-sas.html
Of course, you don't explain anything, you just jump into the code without explanation. So, please explain the purpose of this macro, without reference to code. Don't make us guess. Don't waste our time by making us figure out what you really are doing, when you already know what you really are doing and could tell us.
... View more