Desktop productivity for business analysts and programmers

Date extension from todays date in months to create a date into future for

Reply
Contributor
Posts: 23

Date extension from todays date in months to create a date into future for

Hi All,

 

im new to programming and only recently been trained in programming in SAS ( a couple of months )

i have a code that i have been working on and im struck on the last part and would like to post for some ideas to test.

 

i want to create a variable called 'extended date' to add 36 months to today() date. this would be rolling. i also needed to created dates in past, that is the reason for the year=2010

 

data indata;
do year=2010 to year(today());
do month=1 to month(today());
SAS_date=mdy(month,1,year);

output;
end;
end;

format SAS_date date9.;
run;

 

my results so far is below to today()

year month sas_date
2010 1 1-Jan-10
2010 2 1-Feb-10
2010 3 1-Mar-10
2010 4 1-Apr-10
2010 5 1-May-10
2010 6 1-Jun-10
2010 7 1-Jul-10
2011 1 1-Jan-11
2011 2 1-Feb-11
2011 3 1-Mar-11
2011 4 1-Apr-11
2011 5 1-May-11
2011 6 1-Jun-11
2011 7 1-Jul-11

 

 

ideal results would look something like this, taking today's date and then creating the next month for the next 36 months into the future

 

today() is always rolling to next month and extended date is taking today() and adding a month for 36 month into the future

year month sas_date extended date
2016 2 1-Feb-16  
2016 3 1-Mar-16  
2016 4 1-Apr-16  
2016 5 1-May-16  
2016 6 1-Jun-16  
2016 6 1-Jul-16  
2016 6   today() 1-Aug-16
2016 6   1-Sep-16
2016 6   1-Oct-16
2016 6   1-Nov-16
2016 6   1-Dec-16

 

thanks

Thiary

Super User
Posts: 19,146

Re: Date extension from todays date in months to create a date into future for

You have the code for incrementing 36 months from your previous question. 

 

Is it the next 6 months your looking for? To the end of the year? I can see your output but don't understand the logic. 

Contributor
Posts: 23

Re: Date extension from todays date in months to create a date into future for

Hi,

im trying to create a date from today () to 36 month forward into the future.

 

those dates are from the past as i also need to get a date from a certain date in the past to today. this part i already figured out

 

 

thanks

 

Super User
Posts: 7,431

Re: Date extension from todays date in months to create a date into future for

As shown in the other thread that was referenced, use the intnx() function to increment dates.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 19,146

Re: Date extension from todays date in months to create a date into future for

Why are the questions essentially identical?

Contributor
Posts: 23

Re: Date extension from todays date in months to create a date into future for

i think maybe a friend is trying to help me and i didnt know they also posted here

Super User
Posts: 19,146

Re: Date extension from todays date in months to create a date into future for

Data want;
Do I=1 to 36;

    Date=INTNX ('month', today(), I, 'b');
    OUTPUT;

end;
format date date9.; Run;

This creates a dataset with dates incrementing up to 36 months in the future. 

Contributor
Posts: 23

Re: Date extension from todays date in months to create a date into future for

hello Reeza,

 

thanks, this helps. Tested,it created the next 36 months.

i will combine by code to get historical dates and future dates

 

thank you for your help!!!!...

 

 

Super User
Posts: 19,146

Re: Date extension from todays date in months to create a date into future for

So either this is a homework question or you have two accounts?

 

https://communities.sas.com/t5/Base-SAS-Programming/How-to-take-today-date-36-months-into-future/m-p...

Contributor
Posts: 23

Re: Date extension from todays date in months to create a date into future for

this is not me, i only have one account.

Ask a Question
Discussion stats
  • 9 replies
  • 496 views
  • 0 likes
  • 3 in conversation