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
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
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).
HI
is it like this 05/30/15 18:25:00 -120 = 05/30/15 18:23:00 ?
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
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
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.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.