DATA Step, Macro, Functions and more

How to take today date + 36 months into future

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

How to take today date + 36 months into future

Hi SAS gurus,

 

May I ask one question how to take today date + 36 months into future? Using the variable below SAS_extension? 

 

data in.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;

 

SAS_extension= SAS_date+36 months *** I would like to take today date + 36 months into future


Accepted Solutions
Solution
‎06-30-2016 07:20 PM
Super User
Posts: 19,855

Re: How to take today date + 36 months into future

INTNX - note the 4th/last parameter aligns it, in this case, I've chosen the beginning of the month. You can choose, end or same. Look up the values in the documentation.

 

date_future36=intnx('month', today(), 36, 'b')

View solution in original post


All Replies
Solution
‎06-30-2016 07:20 PM
Super User
Posts: 19,855

Re: How to take today date + 36 months into future

INTNX - note the 4th/last parameter aligns it, in this case, I've chosen the beginning of the month. You can choose, end or same. Look up the values in the documentation.

 

date_future36=intnx('month', today(), 36, 'b')
Respected Advisor
Posts: 4,930

Re: How to take today date + 36 months into future


data in.indata;

                do year=2010 to year(today());

                                do month=1 to month(today());

                                                SAS_date=mdy(month,1,year);                                                                     

                                                output;

                                end;

                end;

run;

 


are you sure this is what you want?

 

do month=1 to month(today())

 

will return only the months from January to, say, June for ALL years.

 

To get all months, you would do better with:

 

SAS_date = '01JAN2010'd;
do while ( SAS_date <= intnx("MONTH", Today(), 0) );
	SAS_date = intnx("MONTH", SAS_date, 1);
	output;
	end;

 

 

PG
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 279 views
  • 7 likes
  • 3 in conversation