BookmarkSubscribeRSS Feed
radhikaa4
Calcite | Level 5

I have one datetime variable and I would like to add 7 days to the existing date/time

 

patientIDraw_start_date_timenew_start_date-time
112/4/2019  15:21 PM12/5/2019  15:21 PM
212/5/19 12:42 PM12/12/19 12:42 PM

 

I did the following and didn't work

new_start_date = intck ('dtday', raw_start_date_time, 7)

 

I also tried intck('day'), intnx ('day'), and raw_start_date_time * 7 * 24 * 60 * 60.

 

No luck

3 REPLIES 3
Reeza
Super User

INTNX, not INTCK() and dtDAY since you have a datetime.

new_start_date = intnx('dtday', raw_start_date_time, 7);

If you wanted to do it manually you need to ADD that date amount, not multiply it.

 

 raw_start_date_time  +  7 * 24 * 60 * 60
Tom
Super User Tom
Super User

INTCK() counts intervals.  You want INTNX().

Also are variables really datetime and not string?  I don't think SAS has a format to display datetime values in that style you are showing.  But perhaps that is data you typed into Excel instead?

Peter_C
Rhodochrosite | Level 12
New = raw+ 7 *24*3600 ;
A SAS datetime value is an integer number of seconds.
There are 3600 seconds in each of the 24 hours in a day

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 6437 views
  • 0 likes
  • 4 in conversation