|
Hi Kieth -
SAS has three time constant types, one for times, one for dates, and
one for date/times. Times are the number of seconds since midnight.
Dates are the number of days since 1/1/60. Datetimes are the number
of seconds since 1/1/60.
You can create a date or a datetime value directly
time='16:37:56't;
date='27DEC2002'd;
DT='27DEC2002:16:37:56'dt;
which have values of time=59876, date=15701, and dt=1356626276.
You need to read your date and time values and create a datetime value
using date, time, and datetime informats and formats.
======program=======
DATA jobswait;
INPUT JDATE JULIAN5.
ATIME TIME11.2;
timevar=input(put(jdate,date7.)||':'||put(atime,time11.2),datetime20.);
cards;
02361 05:25:22.00
03001 16:37:56.00
02361 16:37:56.00
;
proc print;
var JDATE ATIME timevar;
proc print;
var JDATE ATIME timevar;
format JDATE yymmdd8. ATIME time. timevar datetime22.;
run;
======output=======
obs JDATE ATIME timevar
1 15701 19522 1356585922
2 15706 59876 1357058276
3 15701 59876 1356626276
Obs JDATE ATIME timevar
1 02-12-27 5:25:22 27DEC2002:05:25:22
2 03-01-01 16:37:56 01JAN2003:16:37:56
3 02-12-27 16:37:56 27DEC2002:16:37:56
====================
in the assignment
timevar=input(put(jdate,date7.)||':'||put(atime,time11.2),datetime20.);
your SAS date and time values are being written out in date and time
formats with an ":" stuck in-between ("27DEC2002:16:37:56") and read
back into SAS as a datetime.
Hope that's not too confusing.
PC
kmcwhort@STATE.GA.US (Keith McWhorter) wrote in message news:<3E7B213B.B4D1EAAA@state.ga.us>...
> Hey,
>
> Be nice - I'm a SAS newbie! :-) I want to do a calculation on length of
> time, but since some of my observations cross midnight, I feel I need to
> have the date and time together to do the math. I've got about 5 SAS
> books open on my desk trying to feel my way through this program! (This
> is SAS 8.2 on OS/390 2.10)
>
> My input is this:
>
> DATA jobswait;
> INFILE 'SGSS.KEITH.ALLOC';
> INPUT @44 SYSID $4. @53 JDATE JULIAN5. @59 ATIME TIME11.2
> @71 JOBNO $8. @98 JobName $8.;
> IF JobName=: 'DMD';
> JNN = jobname || jobno;
>
> I'm then sorting on the new variable JNN. I want to take the first and
> last occurances and get the difference in the time (duration). I don't
> know how to combine my date and time to one variable to do the math on.
>
> For your enjoyment, here's the rest of the code as it is so far...
>
> PROC SORT data=jobswait;
> BY JNN atime;
>
> DATA jobsone;
> SET jobswait;
> BY JNN;
> RETAIN dur;
> IF first.jnn THEN DO;
> DUR = .;
> start = atime;
> END;
> IF last.jnn THEN DO;
> dur = SUM(atime - start);
> jname = substr(jnn,1,8);
> jno = substr(jnn,9,8);
> output;
> END;
>
> Can anyone help?
> Thanks!!!
>
> Keith McWhorter
> Georgia Technology Authority
> 404-656-9068
|