Turn on suggestions

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

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Manipulating SAS Dates

Options

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

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 02-01-2016 05:24 PM
(1321 views)

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

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

9 REPLIES 9

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hello @robertrao,

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

Thanks

Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

**Available on demand!**

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.