If YTD is what is being asked for, no looping needed, no macro needed.
See https://communities.sas.com/t5/SAS-Enterprise-Guide/Last-month-and-YTD-data/m-p/829569#M41275
In that thread, the input data was three letter month names (Jan, Feb, etc.) so that's what the code uses. Its even simpler if you have actual SAS date or date/time values.
... View more