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: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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