SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Adding days to a DATETIME value?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

Adding days to a DATETIME value?

I have a macrovariable called &filterdate_start. It's DATETIME20 and has the value 26NOV2012:00:00:00.

I need a new macrovariable called &filterdate_end to equal &filterdate_start + 2 days, with the value 28NOV2012:00:00:00.

What's the most practical way to add 2 days to a DATETIME20 value?


Accepted Solutions
Solution
‎12-03-2012 06:55 AM
Super User
Posts: 5,424

Re: Adding days to a DATETIME value?

Posted in reply to TurnTheBacon

If you want the same time of day, just add 2 * 24 * 60 * 60.

Data never sleeps

View solution in original post


All Replies
Solution
‎12-03-2012 06:55 AM
Super User
Posts: 5,424

Re: Adding days to a DATETIME value?

Posted in reply to TurnTheBacon

If you want the same time of day, just add 2 * 24 * 60 * 60.

Data never sleeps
Frequent Contributor
Posts: 106

Re: Adding days to a DATETIME value?

Posted in reply to TurnTheBacon

I'd use one of SAS's most powerful date/datetime functions: INTNX

Somewhat like

%let filterdate_end = %sysfunc( intnx( dtday, "&filterdate_start"dt, 2 ) , datetime20. ) ;

Two assumptions here: &filterdate_start is the formatted datetime value, &filterdate_end is expected to be in datetime20. format.

If not then

%let filterdate_end = %sysfunc( intnx( dtday, &filterdate_start, 2 ) ) ;

will do and return the result as the number of seconds since SAS epoch (formatting then left to you).

🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 7061 views
  • 0 likes
  • 3 in conversation