I want to create a table that create a window of date from in initial date by moving forwad and retreat by month
I have the following data
data HAVE;
input id :best32. caldt :mmddyy10. ;
format caldt date9.;
datalines;
1 1/1/2013
2 2/1/2014
;
run;
data want;
input id :best32. newcaldt :mmddyy10. ;
format newcaldt date9.;
datalines;
1 11/1/2012
1 12/1/2012
1 1/1/2013
1 2/1/2013
1 3/1/2013
2 11/1/2013
2 12/1/2013
2 2/1/2014
2 3/1/2014
2 4/1/2014
;
run;
Your example data implies that you want the beginning of the month for two months prior and two months after the date. If that is the complete rule then this does that:
data want; set have; format newcaldt date9.; do i=-2 to 2; newcaldt= intnx('month',caldt,i,'B'); output; end; drop i; run;
I left in the original date variable so you could verify what is going on.
data want;
set have;
do month=-2 to 2 by 1;
newcaldate=intnx('month',caldt,month,'b');
output;
end;
format newcaldate mmddyy10.;
drop month caldt;
run;
By the way, I think you typed the dates in the want data set incorrectly, if I am understanding the problem correctly.
Your example data implies that you want the beginning of the month for two months prior and two months after the date. If that is the complete rule then this does that:
data want; set have; format newcaldt date9.; do i=-2 to 2; newcaldt= intnx('month',caldt,i,'B'); output; end; drop i; run;
I left in the original date variable so you could verify what is going on.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.