turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Data Management
- /
- Forum
- /
- Equivalence using DATETIME

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-09-2015 08:50 PM

I have code that does the following sort of thing over and over:

if SUBJECT_NUMBER='300-0010' then do;

if input ('19AUG15:07:52:00', DateTime18.) <= Event_Time <= input ('20AUG15:07:30:00', DateTime18.) then AUC_Day_1 = 1;

if input ('20AUG15:07:30:00', DateTime18.) <= Event_Time <= input ('21AUG15:07:45:00', DateTime18.) then AUC_Day_2 = 1;

end;

I expect the result to look like this

Day_1 Day_2

1 .

1 .

1 .

1 1

. 1

. 1

. 1

In other words, the largest value in one interval and the smallest value in the other are the same. So one will be 1 and the other will be missing except for when we hit that one overlapping value, at that point both Day_1 and Day_2 should be 1.

Mysteriously, sometimes I get the above but sometimes I don't and instead get only one of the other with a value of 1 at the point where the intervals overlap.

It's basically like

if 5 <= x <= 10 then S = 1;

if 10 <= x <= 20 then T = 1;

It seems to me that when x is 10, both S and T must be 1. And yet I'm only getting it some of the time. It's not typos on the datetimes that overlap because I'm copying them from elsewhere and then pasting them in the two places in the code. And plus I can look at them with my eyes and see they are the same. I am mystified. Any help is greatly appreciated.

Accepted Solutions

Solution

09-25-2015
06:23 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-09-2015 11:06 PM

OK, then it could be that Event_Time is not always an integer. This happens to me when I import/convert dates from Excel. Try this then:

```
if SUBJECT_NUMBER='300-0010' then do;
if '19AUG15:07:52:00'DT <= round(Event_Time) <= '20AUG15:07:30:00'DT then AUC_Day_1 = 1;
if '20AUG15:07:30:00'DT <= round(Event_Time) <= '21AUG15:07:45:00'DT then AUC_Day_2 = 1;
end;
```

PG

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-09-2015 10:12 PM

If Event_Time is a SAS datetime, then you should compare it with SAS datetime constants, like this:

```
if SUBJECT_NUMBER='300-0010' then do;
if '19AUG15:07:52:00'DT <= Event_Time <= '20AUG15:07:30:00'DT then AUC_Day_1 = 1;
if '20AUG15:07:30:00'DT <= Event_Time <= '21AUG15:07:45:00'DT then AUC_Day_2 = 1;
end;
```

(untested)

PG

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-09-2015 10:48 PM

Thanks for the suggestion but when I try it that way I get the same result, namely some are good and some are not. I notice that the example code I posted happened to be one of the good ones so here is one of the bad ones to balance it out, although why one is good and one is bad is a mystery to me. I'll post it both the way I originally coded it and with the DT suggestion.

if SUBJECT_NUMBER='300-0002' then do;

if '12AUG15:08:10:00'DT <= Event_Time <= '13AUG15:07:10:00'DT then AUC_Day_1 = 1;

if '13AUG15:07:10:00'DT <= Event_Time <= '14AUG15:09:36:00'DT then AUC_Day_2 = 1;

end;

if SUBJECT_NUMBER='300-0002' then do;

if input ('12AUG15:08:10:00', DateTime18.) <= Event_Time <= input ('13AUG15:07:10:00', DateTime18.) then AUC_Day_1 = 1;

if input ('13AUG15:07:10:00', DateTime18.) <= Event_Time <= input ('14AUG15:09:36:00', DateTime18.) then AUC_Day_2 = 1;

end;

Solution

09-25-2015
06:23 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-09-2015 11:06 PM

OK, then it could be that Event_Time is not always an integer. This happens to me when I import/convert dates from Excel. Try this then:

```
if SUBJECT_NUMBER='300-0010' then do;
if '19AUG15:07:52:00'DT <= round(Event_Time) <= '20AUG15:07:30:00'DT then AUC_Day_1 = 1;
if '20AUG15:07:30:00'DT <= round(Event_Time) <= '21AUG15:07:45:00'DT then AUC_Day_2 = 1;
end;
```

PG

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-09-2015 11:17 PM

Beautiful! That works perfectly. Thanks a lot.