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 open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.