Hello, I can not understand why cat does not take into account the zeros in this example. The length of the macro variable x3 is 2 for months <10 after put (x2,Z2.).
Another question, why the repeat function when the number of repetitions equal to 0 adds the 0 (which explains the use of the loop) %macro remplir();
%DO LOOP=7 %to 12;
%LET x1=%SYSFUNC(INTNX(month,%SYSFUNC(INTNX(day,%SYSFUNC(today()),%SYSFUNC(day(%SYSFUNC(today())))-1)),&LOOP.-19));
%LET x2=%SYSFUNC(MONTH(&x1.));
%LET x3=%SYSFUNC(PUTN(&x2., Z2.));
%let len=%length(&x3.);
%let len1=%length(&x2.);
%LET val1=&x1.;
%LET val12=%SYSFUNC(CAT(%SYSFUNC(PUTN(&x1.,year2.)),M,&x3.));
%LET val13=%SYSFUNC(CAT(%SYSFUNC(PUTN(&x1.,year2.)),M,%sysfunc(repeat(0,%eval(2-%length(&x2.)))) ,&x2.));
%if &len1.=1 %then %do;
%LET val14=%SYSFUNC(CAT(%SYSFUNC(PUTN(&x1.,year2.)),M,%sysfunc(repeat(0,%eval(2-%length(&x2.)))) ,&x2.));
%end;
%else %do;
%LET val14=%SYSFUNC(CAT(%SYSFUNC(PUTN(&x1.,year2.)),M,&x3.));
%end;
%put &=x3/&=len./&=val12./&=val12./&=val13./&=val14.;
%end;
%mend remplir;
%remplir; /**************/ Log /*************/ Log X3=11/LEN=2/VAL12=16M11/VAL12=16M11/VAL13=16M011/VAL14=16M11 X3=12/LEN=2/VAL12=16M12/VAL12=16M12/VAL13=16M012/VAL14=16M12 X3=01/LEN=2/VAL12=17M1/VAL12=17M1/VAL13=17M01/VAL14=17M01 X3=02/LEN=2/VAL12=17M2/VAL12=17M2/VAL13=17M02/VAL14=17M02 X3=03/LEN=2/VAL12=17M3/VAL12=17M3/VAL13=17M03/VAL14=17M03 X3=04/LEN=2/VAL12=17M4/VAL12=17M4/VAL13=17M04/VAL14=17M04 cordially
... View more