Thanks, Reeza this article helped me a lot, after reading it I actually achieve what I wanted, here’s the final code:     options nodate nonumber nocenter formdlim="-";
data a;
  input  date var_a;
format date ddmmyy10.;         
datalines;
22101 1
22101 1
22101 1
22101 1
22101 1
22100 1
22100 1
22100 1
22100 1
22100 1
22100 1
22099 1
22099 1
22099 1
22099 1
22099 1
22099 1
22099 1
;
run;
proc sql;
select date,
var_a
from work.a;
quit;
data b;
format date ddmmyy10.;
var_a = .;
run;
proc sql;
delete from b;
quit;
%let now = today();
%put &now;
%macro insert;
%do i = 1 %to 5;
	proc sql;
	insert into b
	select * from a
	where date < intnx('day', intnx('day', today(), -5), &i);
	quit;
%end;
%mend;
%insert 
						
					
					... View more