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
It should, but you should always check. Also, make sure your condition is exactly what you want, ie GE vs GT.
It should, but you should always check. Also, make sure your condition is exactly what you want, ie GE vs GT.
Hello @robertrao,
Yes, this should work, provided that your criterion is "at least 24 hours prior to ..."
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;
The formula you showed in your question isn't the one you coded in your code above.
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;
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;
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.