BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasphd
Lapis Lazuli | Level 10

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

 

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
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. 

--
Paige Miller
ballardw
Super User

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.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 757 views
  • 1 like
  • 3 in conversation