DATA Step, Macro, Functions and more

Trying to Exclude Negative Time differences

Reply
Frequent Contributor
Posts: 78

Trying to Exclude Negative Time differences

I'm trying to exclude negative time differences only when the time goes from somewhere in the 23:00 hour to the 00:00 hour. I can't seem to get this code right. Unfortunately, I do not have dates associated with the times or that would solve everything. Here is the code I'm working with:


DO I=1 TO 72;
IF DECONSET{I} NE . AND (DECONSET{I+1}-DECONSET{I}<=0) AND (DECONSET{I+1}-DECONSET{I} NE .) THEN PUT READER= CUSTOMID= DECONSET{I}= DECONSET{I+1}=;
END;

I don't want this code to output the times that go from 23:00 to 00:00. I tried writing in the code to exclude differences less than -83000 when '23:00't<=DECONSET{I}<='23:59't , but that didn't seem to work.

Thanks in advance for your help!


Message was edited by: statadm

Message was edited by: statadm Message was edited by: statadm
Frequent Contributor
Posts: 78

Re: Trying to Exclude Negative Time differences

skip Message was edited by: statadm
Super Contributor
Super Contributor
Posts: 3,174

Re: Trying to Exclude Negative Time differences

Read this prior post with guidelines for special character conditions.

Scott Barry
SBBWorks, Inc.

http://support.sas.com/forums/thread.jspa?messageID=27609
Frequent Contributor
Posts: 78

Re: Trying to Exclude Negative Time differences

Thanks Scott, I figured it was something like that. It is working now.
Frequent Contributor
Posts: 78

Re: Trying to Exclude Negative Time differences

Does anyone have any idea how I can add something to my code to exclude times that go over the midnight hour?
Valued Guide
Posts: 2,177

Re: Trying to Exclude Negative Time differences

> I'm trying to exclude negative time differences only
> when the time goes from somewhere in the 23:00 hour
> to the 00:00 hour. I can't seem to get this code
> right. Unfortunately, I do not have dates associated
> with the times or that would solve everything. Here
> is the code I'm working with:
>
>
> DO I=1 TO 72;
> IF DECONSET{I} NE . AND
> (DECONSET{I+1}-DECONSET{I} le 0) AND
> (DECONSET{I+1}-DECONSET{I} NE .) THEN PUT READER=
> CUSTOMID= DECONSET{I}= DECONSET{I+1}=;
> END;
>
> I don't want this code to output the times that go
> from 23:00 to 00:00. I tried writing in the code to
> exclude differences less than -83000 when
> '23:00't le DECONSET{I} le '23:59't , but that
> didn't seem to work.
>
> Thanks in advance for your help!
are we to assume your array DECONSET contains up to 72 times that represent consecutive events and you want to treat over midnight in a proper way so that if difference is negative and prior time is after 11pm then adapt the negative difference into a proper duration over midnight?
Instead of testing deconset(i) and using deconset(i+1) I would suggest testing deconset(i+1)
something like[pre]array interval(2:72) ;* to keep the calculations;
do i=2 to 72 ;
if missing(deconset(i-1)) then continue ;
if missing(deconset(i)) then continue ; * testing both allows occasional gaps;
inter = deconset(i) - deconset(i-1) ;
if inter LT 0 then do ;
if deconset(i) GE '23:0:0't then
inter = inter + '24:0:0't ;
if interval LT 0 then do ;
inter = . ;
put ( deconset(i-1) deconset(i) )(=) ' still negative interval' ;
end ;
interval(i) = inter ;
end ; [/pre] is that helpful?

That measures interval between consecutive pairs which are both non-missing..
An alternative model might measure between the latest and previous non-missing value.

peterC
Frequent Contributor
Posts: 78

Re: Trying to Exclude Negative Time differences

Thanks Peter, I will give this code a try.
Ask a Question
Discussion stats
  • 6 replies
  • 365 views
  • 0 likes
  • 3 in conversation