Date: Wed, 29 Oct 2003 16:45:17 +0000
Reply-To: sashole@bellsouth.net
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Paul Dorfman <paul_dorfman@HOTMAIL.COM>
Subject: Re: Subtracting time in minutes
Content-Type: text/plain; format=flowed
Sharon,
Read the date values using the date informat MMDDYY8. to produce
corresponding SAS date values; read the time values using the time informat
TIME8. to produce SAS time values:
nromdate = input (romdate, mmddyy8.) ;
ndeldate = input (deldate, mmddyy8.) ;
nromtime = input (romtime, time8.) ;
ndeltime = input (deltime, time8.) ;
Combine the dates and times into correspondiong datetime values, a datetime
value being merely a number of seconds elapsed from the beginning of January
1, 1960. You can either do it directly:
nromdatetime = nromdate * 86400 + nromtime ;
ndeldatetime = ndeldate * 86400 + ndeltime ;
(think for a minute why these formulae hold and whence the 86400 comes) or
using the DMHS() function:
nromdatetime = dhms (nromdate , 0 , 0 , nromtime) ;
ndeldatetime = dhms (ndeldate , 0 , 0 , ndeltime) ;
Finally, the second difference will be simply
diff = ndeldatetime - nromdatetime ;
Of course, the entire thing can be combined into a single expression if so
desired:
diff = ( input (deldate, mmddyy8. ) - input ( romdate, mmddyy8.) ) * 86400 +
input (deltime, time8. ) - input ( romtime, time8.) ;
Kind regards,
=================
Paul M. Dorfman
Jacksonville, FL
=================
>From: Sharon Alexander <Sharon.Alexander@HCCSJ.NF.CA>
>Reply-To: Sharon Alexander <Sharon.Alexander@HCCSJ.NF.CA>
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Subtracting time in minutes
>Date: Wed, 29 Oct 2003 10:55:36 -0330
>
>Hello everyone
>
>I have a file with date/time fields which I converted from character fields
>reading a length 17 to date fields using the following method:
>
>nromtime = input(romtime, mmddyy17.);
>ndeltime = input(deltime,mmddyy17.);
>
>I want to subtract these to get the number of minutes from ROMtime to
>Deltime (Delivery).
>
>Obs ROMTIME DELTIME nromtime ndeltime
>
> 2108 02/04/02 13:40:00 02/04/02 16:44:00 15375
>15375
> 2109 05/24/02 19:35:00 05/25/02 00:46:00 15484
>15485
> 2110 12/01/02 00:00:00 12/02/02 18:24:00 15675
>15676
>
>Only the dates are reading at the moment and not the time. I can't seem to
>get INTCK to work either.
>
>How do I extract time in order to get the number of hours. Should the
>input statement be altered? Substring instead? I work with dates very
>infrequently as you can tell.
>
>Any help would be appreciated.
>
>Sharon
_________________________________________________________________
Enjoy MSN 8 patented spam control and more with MSN 8 Dial-up Internet
Service. Try it FREE for one month! http://join.msn.com/?page=dept/dialup