Search code examples
if-statementsasdatastep

Flagging Lines Below HHMM Threshold SAS IF/THEN Data Statement


I have a dataset where I calculated the number of total hours it took to process a request in hours. A request should be completed in 72 hours, or else if an extension is requested a request should be completed in 408 hours (14 days plus 72 hours).

I need to flag values with a Y or N depending if they meet these criteria.

My problem is that it is only recognizing negative HHMM values as below threshold, not a value like 29:15 which would represent 29 hours 15 minutes. This is less than 72 hours and should be marked "Y" indicating it is timely, but it is marking it "N".

This is what I tried so far:


data work.tbl_6;
set work.tbl_6;

if was_a_timeframe_extension_taken_ = "N" and time_to_notification <= 72 then notification_timely="Y";
else if was_a_timeframe_extension_taken_ = "Y" and time_to_notification <= 408 then notification_timely="Y";
else notification_timely="N";

run;

Can someone advise what could be going wrong here?


Solution

  • This assumes you have data as a SAS time. If you do not you'll need to use INPUT() to do some conversions.

    You need to specify time values using the t after to specify a time constant.

    if was_a_timeframe_extension_taken_ = "N" and time_to_notification <= '72:00't then notification_timely="Y";
    

    SAS stores times as the number of second so you could also convert 72 hours to the number of seconds and use that value.

    if was_a_timeframe_extension_taken_ = "N" and time_to_notification <= (72*60*60) then notification_timely="Y";
    

    EDIT: In general, this style of programming is dangerous and makes it harder to debug your code. If you can avoid it, I would highly recommend it. Instead, give each data set a unique name or keep adding to the previous data step.

      data work.tbl_6;
      set work.tbl_6;