BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BETO
Fluorite | Level 6

hi I have a table that has a startdate/time I'm being ask to give it a 2 min buffer I need to reduce 2 min from it... Prefer as a data step if easier ....thanks

Example

ID.   Datetime     

A      05/01/15 15:25:00

what I need

id.       datetime

A.         05/01/15 15:23:00

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

No need to bother with datetime internal representation, substract a time constant (thanks Jag)

data dates;

input ID$   Datetime & :anydtdtm20.;

new_date = datetime - '00:02:00't;

format datetime new_date datetime20.;

datalines;

A      05/01/15 15:25:00

;

proc print; run;

PG

PG

View solution in original post

6 REPLIES 6
jakarman
Barite | Level 11

120 seconds to substract  (see the basics of datetime).  If you prefer working on intervals you could use that also having the option of dropping time (eg non office hours). 

---->-- ja karman --<-----
BETO
Fluorite | Level 6

HI

is it like this 05/30/15 18:25:00 -120 = 05/30/15 18:23:00 ?

Jagadishkatam
Amethyst | Level 16

You could also use intnx function

data dates;

input ID$   Datetime : anydtdte20.;

new_date=intnx('second',datetime,-120,'same');

format datetime new_date datetime20.;

cards;

A      05/01/15 15:25:00

;

Thanks,

Jag

Thanks,
Jag
PGStats
Opal | Level 21

No need to bother with datetime internal representation, substract a time constant (thanks Jag)

data dates;

input ID$   Datetime & :anydtdtm20.;

new_date = datetime - '00:02:00't;

format datetime new_date datetime20.;

datalines;

A      05/01/15 15:25:00

;

proc print; run;

PG

PG
jakarman
Barite | Level 11

Correct PGstats, your example is showing the usage of knowing the internal representation in a way not being aware it anymore.
It is having:

- a datetime variable being input from a string. That internal representation is a counter based on seconds. (1jan1960)

- substracting those 120 seconds as a converted string being defined as string-time constant

This will be a new valid datetime variabele wit a value as OP's wanted.


Not being aware why something is working is making it difficult to explain to the newbies.
This is having a good background not everything is having a background and can be explained or is having a reason.
    

---->-- ja karman --<-----
Kurt_Bremser
Super User

The secret behind it all is that SAS stores dates as simple numbers, counting the days from 01/01/1960. Similarly, datetimes (and times) are stored as numbers counting seconds.

Therefore, '00:02:00't and 120 are the same constant.

What is needed is to correctly input date/datetime/time values into a SAS dataset, using the proper informat.

As shown by

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 2048 views
  • 2 likes
  • 5 in conversation