BookmarkSubscribeRSS Feed
Ken_oy
Fluorite | Level 6
I have a variable "TIME", format "DATETIME18."

How can I calculate Time1-Time2?
For example:

19JAN07:22:00:00 - 19JAN07:16:00:00?

I try to minus them directly, but I get " 1484863200", useless....

Thanks! Message was edited by: Ken_oy
8 REPLIES 8
deleted_user
Not applicable
Have you tried applying a DATETIME18. format to the difference?
Ken_oy
Fluorite | Level 6
It won't work for me. I tried both of the following:
(Sorry, mistakes in my code, skip this post pls)
--------------------------------------------------------

data insulin_l;
format ltime datatime18.;
set insulin;
ltime=lag(ttime);
ldose=lag(dose);
run;
--------------------------------------------------------
data insulin_l;
set insulin;
ltime=lag(ttime);
ldose=lag(dose);
format ltime datatime18.;
run;
--------------------------------------------------------

Message was edited by: Ken_oy Message was edited by: Ken_oy
deleted_user
Not applicable
Well, it that was a literal cut & paste, you need to use datEtime18 and not "datatime18"
Ken_oy
Fluorite | Level 6
Sorry, my bad.
I am using the following code now
--------------------------------------------------
data insulin_l;
set insulin;
ltime=ttime-lag(ttime);
ldose=dose-lag(dose);
format ltime datetime18.;
run;
-------------------------------------------

But the answer is:

18JAN07:20:00:00 - 19JAN07:08:00:00

= 31DEC59:12:00:00
----------------------------------
1959?? What I want is the difference between those time points.

Thanks, Kmg!
deleted_user
Not applicable
Yes, I wasn't thinking this through correctly.

Please check out the SAS function INTCK (or DATDIF if you are only interested in the number of days).
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Referencing the SAS support http://support.sas.com/ website, here are some useful reading links on SAS DATE and DATETIME variables.

Scott Barry
SBBWorks, Inc.

SAS(R) 9.2 Language Reference: Concepts
About SAS Date, Time, and Datetime Values
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002200738.htm


WORKING WITH SAS® DATE AND TIME FUNCTIONS
Andrew H. Karp
Sierra Information Services, Inc.
San Francisco, California USA
http://www2.sas.com/proceedings/sugi24/Begtutor/p58-24.pdf
Ken_oy
Fluorite | Level 6
Thanks everyone!

By using:

w=intck('minute', ttime, lag(ttime));
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
I believe you want "dtminute" not "minute" when working with INTCK and DATETIME variables (as opposed to TIME variables). If you were to perform the calculation and then use a FORMAT statement for the difference variable, apply a FORMAT to that variable, I believe you would see the incorrect result reflected in the log.

Scott Barry
SBBWorks, Inc.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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