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
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Manipulating SAS Dates

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

02-01-2016 05:24 PM - last edited on 02-01-2016 09:33 PM by Reeza

Hello,

I have two SAS datetimes as shown below:

I have an array of med_Time dates and want to output if med_times was **24 hours/1 day** prior to LAB_order_TIME

MED_TIME1 LAB_ORDER_TIME

24JAN2015:20:07:00.000 23JAN2015:05:54:00.000

if ( LAB_ORDER_TIME - MED_TIME) /(60*60) ge 24

I tried this above and not sure if i am doing it right....Would this give me the result i am looking for??

Thanks

Accepted Solutions

Solution

02-01-2016
05:46 PM

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

02-01-2016 05:32 PM

All Replies

Solution

02-01-2016
05:46 PM

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

02-01-2016 05:32 PM

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

02-01-2016 05:33 PM

Hello @robertrao,

Yes, this should work, provided that your criterion is "at least 24 hours prior to ..."

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

02-01-2016 06:34 PM

Hello ,

Sorry to add this question after having been answered.

I try to do the below and it would not somehow work for me.

Wanted to create a new varibles **new_lax{} and new_time{ } for those satisfying my condition.**

**It would not somehow work. Could you please point out the mistake in the below code.**

**Thanks a lot**

**data** final;

set orders_lax;

by pat_enc_csn_id; ** /*multiple records per ID exist*/**

array names(*) laxname1-laxname380; ** /*med names*/**

array times(*) $ laxtime1-laxtime380; ** /*med taken time*/**

array new_lax(*) $ new_lax1-new_lax100; **/*new variables which satisfied condition*/**

j=**1**;

do i= **1** to **380**;

if order_time-times{i} ge **24** then do; **/*order_time is a variable existing in dataset */**

new_Lax{j}=names{i};

new_time{j}=times{i};

j+**1**;

end;

drop i j;

end;

**run**;

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

02-01-2016 06:40 PM

The formula you showed in your question isn't the one you coded in your code above.

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

02-02-2016 12:42 AM

Oops. Sorry about that. Thias code is working fine but its bringing in the ones satisfying the condition as well mas others.

Could you help me grab only those which are satisfying the condition?

Thanks

**data** final

set orders_lax;

array names(*) laxname1-laxname380; /*med names*/

array times(*) $ laxtime1-laxtime380; /*med taken time*/

array new_lax(*) $ new_lax1-new_lax380; /*new variables which satisfied condition*/

array new_time(*) new_time1-new_time380;

j=**1**;

do i= **1** to **380**;

if order_time-times{i}/**60*****60** ge **24** then do; /*order_time is a variable existing in dataset */

new_Lax{j}=names{i}; ** /*condition satisfied*/**

new_time{j}=times{i}; ** /*condition satisfied*/**

end;

j+**1**;

drop i j;

format new_time1-new_time350 datetime.;

end;

**run**;

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

02-02-2016 04:25 AM

Your latest correction is still insufficient: You forgot two pairs of parentheses (cf. your first post in this thread):

`if (order_time-times{i})/(60*60) ge 24 then do;`

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

02-02-2016 06:56 AM

Hi Freelance, tried adding ,removing those braces but the result would not change...

Thanks

Thanks

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

02-02-2016 07:56 AM

The inequality with the parentheses means: times{i} was at least 24 hours prior to order_time.

The inequality without parentheses means: times{i} was at least 24 **seconds** prior to order_time.

Please note that the former inequality implies the latter. That is, if all medication times were at least 24 hours prior to order time, the results would not change indeed, whether you use the correct or the incorrect formula.

But you wrote that your code would be "bringing in the ones satisfying the condition as well mas others." Could you please show us one of those "other" cases?

Also, if you are more comfortable with SAS functions than with mathematical formulas, you could rewrite your IF condition as follows:

`if intck('hour', times{i}, order_time, 'c') ge 24 then do;`

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

02-02-2016 07:03 AM

Well you don't exclude them anywhere. Try adding an explicit OUTPUT statement or an explicit DELETE.