BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8

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
Reeza
Super User

It should, but you should always check. Also, make sure your condition is exactly what you want, ie GE vs GT.

 

View solution in original post

9 REPLIES 9
Reeza
Super User

It should, but you should always check. Also, make sure your condition is exactly what you want, ie GE vs GT.

 

FreelanceReinh
Jade | Level 19

Hello @robertrao,

 

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

robertrao
Quartz | Level 8

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;

Reeza
Super User

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

robertrao
Quartz | Level 8

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;

FreelanceReinh
Jade | Level 19

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;
robertrao
Quartz | Level 8
Hi Freelance, tried adding ,removing those braces but the result would not change...
Thanks
FreelanceReinh
Jade | Level 19

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;
Reeza
Super User
Well you don't exclude them anywhere. Try adding an explicit OUTPUT statement or an explicit DELETE.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1162 views
  • 3 likes
  • 3 in conversation