SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BCNAV
Quartz | Level 8

This is probably an easy answer, but how does one add months to a date variable.

 

Example:

 

suppose date_start='01Aug2015'd and I use this as the ending point for my historical data. When I build my model and use the lead=12 option for my arima forecast, I'd like to be able to use that 12 in the lead statement to autiomatically calculate a bound for using the band command to shade in the forecast area in sgplot.

 

So I need to be able to take that 12 and add it to date_start. I don't seem to be able to use:

 

date_end=date_start + 12,

 

So how can I add twelve months to date_start? I actually have a variable called lead_var that passes the lead value so I can change it in one place as a global variable and it will affect all arima calls. So in effect I need to be able to use:

 

date_end=date_start + lead_var

 

with lead_var=12 in this case.

 

Thanks again for all your help. These forums are amazing!

-Bill

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21
data have;
  input date date9.;
  format date date9.;
  cards;
2feb2017
3apr2016
;
data want;
  set have;
  format newdate date9.;
  newdate=intnx('month',date,12,'s');
run;

Art, CEO, AnalystFinder.com

View solution in original post

2 REPLIES 2
art297
Opal | Level 21
data have;
  input date date9.;
  format date date9.;
  cards;
2feb2017
3apr2016
;
data want;
  set have;
  format newdate date9.;
  newdate=intnx('month',date,12,'s');
run;

Art, CEO, AnalystFinder.com

BCNAV
Quartz | Level 8

thank you!

 

This worked perfectly

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 60919 views
  • 4 likes
  • 2 in conversation