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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: