Using this simple data : data test;
input id date_effet mois_resil;
cards;
1 201701 201801
2 201702 201711
;
run; I just realized I forgot to initialize my variable, here is the revised code : %Macro essai;
data result;
set test;
%do i = 201701 %to 201801;
nb_j_&i. = 0;
%if %substr(&month., 5, 2) = 12 %then %let month = %eval(&month. + 88);
%end;
%let month = 201701;
do until (&month. = mois_resil) ;
if &month. = date_effet then do;
nb_j_&month. = 29;
%let i = %eval(&month. + 1);
do until (&i. = mois_resil) ;
nb_j_&i. = 31;
%let i = %eval(&i. + 1);
%if %substr(&i., 5, 2) = 12 %then %let i = %eval(&i. + 88);
end;
end;
%let month = %eval(&month. + 1);
%if %substr(&month., 5, 2) = 12 %then %let month = %eval(&month. + 88);
end;
nb_j_&month. = 28;
run;
%mend;
%essai; This is the result I want : id date_effet mois_resil nb_j_201701 nb_j_201702 ....... nb_j_201801
1 201701 201801 29 31 28
2 201702 201711 0 29 0 My actual dataset is of course much longer
... View more