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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 978 views
  • 2 likes
  • 5 in conversation