@Patrick's solution to put your code into an actual macro is correct.
But if I'm understanding what you're doing, you're basically taking a date and trying to increment or decrement it by some number of months. In your code, you're doing it 'by hand' by treating the year and month as two different integers. But SAS knows how to work with dates, and has a function, INTNX, which will add a month to a date. It's generally easier (and safer) to let SAS do date calculations rather than write your own.
You can even use the macro language to call the INTNX function. The code gets a bit ugly. But basically, you use the INPUTN function to convert the string 202212 to a SAS date (22980 = 01Dec2022), then use INTNX to increment that date by 2 months (01Feb2023), then use PUTN to format that date as 202302.
%let anomes_execucao = 202212;
%let min_maturidade = 2;
%let anomes_execucao_want= %sysfunc(putn(%sysfunc(intnx(month,%sysfunc(inputn(&anomes_execucao,yymmn6)),&min_maturidade)),yymmn6)) ;
returns:
1 %let anomes_execucao = 202212;
2 %let min_maturidade = 2;
3
4 %let anomes_execucao_want=
4 ! %sysfunc(putn(%sysfunc(intnx(month,%sysfunc(inputn(&anomes_execucao,yymmn6)),&min_maturidade)),yy
4 ! mmn6)) ;
5 %put &=anomes_execucao_want ;
ANOMES_EXECUCAO_WANT=202302
... View more