Help using Base SAS procedures

How to if than time

Accepted Solution Solved
Reply
Regular Contributor
Posts: 240
Accepted Solution

How to if than time

HI ,

i've a question. I have a report that shows all the tickets open in a 24 hr period. If the ticket is open at 8 am thru 8 pm  we have a 4 hr window to work ticket. The issue is if the ticket opens after 8 pm - 8 am  the office is close so the ticket can't be worked within the 4 hr window. I was wondering if there is a way to create an if statement where ticket open at off hrs to  default to 8 am?  For example

the ticket open. At

09Aug 2013 09::24:00 PM   

I Would like to see

10Aug 2013 08:00:00 AM

THanks for your assistance


Accepted Solutions
Solution
‎08-09-2013 05:22 PM
Super User
Posts: 11,343

Re: How to if than time

Something like this perhaps assuming your ticket open datetime variable is named TicketOpen.

if hour(TicketOpen) ge 16 then ActualTicketOpen = DHMS((datepart(TicketOpen)+1),8,0,0);

else ActualTicketOpen=TicketOpen;

Apply the same format to the ActualTicketOpen, or what ever you might decide to call it, as TicketOpen.

Depending on your actual business rulesyou may want to change the GE to GT (or > ) if you do want to have the 09Aug 2012 08:00:00PM treatet as opened on 09 instead of 10 Aug.

View solution in original post


All Replies
Solution
‎08-09-2013 05:22 PM
Super User
Posts: 11,343

Re: How to if than time

Something like this perhaps assuming your ticket open datetime variable is named TicketOpen.

if hour(TicketOpen) ge 16 then ActualTicketOpen = DHMS((datepart(TicketOpen)+1),8,0,0);

else ActualTicketOpen=TicketOpen;

Apply the same format to the ActualTicketOpen, or what ever you might decide to call it, as TicketOpen.

Depending on your actual business rulesyou may want to change the GE to GT (or > ) if you do want to have the 09Aug 2012 08:00:00PM treatet as opened on 09 instead of 10 Aug.

Regular Contributor
Posts: 240

Re: How to if than time

THank you for response I do have a question what does 16 equal to is that military time for 4 o'clock ?

Super Contributor
Posts: 307

Re: How to if than time

You will need to modfiy BallardW's suggestion to deal with calls before 8am. In response to your question, 20:00 hours is 8pm in military time.

Adaptation of Ballardw's code to deal with pre-8am and post-8pm . . .

if hour(TicketOpen) lt 8 then ActualTicketOpen = DHMS((datepart(TicketOpen)),8,0,0);

else if hour(TicketOpen) ge 20 then ActualTicketOpen = DHMS((datepart(TicketOpen)+1),8,0,0);

else ActualTicketOpen=TicketOpen;

Regular Contributor
Posts: 240

Re: How to if than time

Hi Fugue,

Thanks for the response when I run the script I get this out put--- 1691569440 the start date I have is 08aug2013 0;8:24:00 is that a formatting issue ? Thanks again

Regular Contributor
Posts: 240

Re: How to if than time

How can I apply the between statement  to include from 20-23 and from 00 - 8 in hours ? I actually fig it out the format issue an the script works thanks again Is it possible to add the between statement?

Super Contributor
Posts: 307

Re: How to if than time

In a data step, the code would look something like . . .

if 0<= hour(TicketOpen) < 8 then ActualTicketOpen = DHMS((datepart(TicketOpen)),8,0,0);

else if 20<= hour(TicketOpen) <=23 then ActualTicketOpen = DHMS((datepart(TicketOpen)+1),8,0,0);

else ActualTicketOpen=TicketOpen;

Trusted Advisor
Posts: 3,214

Re: How to if than time

Knowing all exceptions opening times etc you can code it all.
An other approach is just keep the INTNX INTCK fucntions. The are meant to deal with time/date shifting.

Using the INTERVALDS option, see SAS(R) 9.3 System Options: Reference, Second Edition. You can define sliding dates /times accourding own definitions. It are some addtional concepts changing releases SAS(R) 9.3 Language Reference: Concepts, Second Edition (datetime concepts) custom intervals. The r445 544 454 options might be also handy.

The concept is: Define a dataset with your valid (opening hours) ordered!. All durations will be adjusted according that  

---->-- ja karman --<-----
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 255 views
  • 3 likes
  • 4 in conversation