I have wagerdatetime variable, and I want to create a new variable timezone, based on the timepart(wagerdatetime):
if 3-9 am, timeslot ="1", 9am-3pm, timeslot="2", 3-9 pm timeslot="3", 9pm-3am, timeslot="4".
The first three are okay, but the 4th one, 9pm-3am the next day, how should I do it?
maybe I should say 0:00:00-3:00:00 & 21:00"00-23:59:59?
if '3:00:00'T <timepart(wagerdatetime) <='9:00:00'T then timeslot="A";
if '9:00:00'T <timepart(wagerdatetime) <='15:00:00'T then timeslot="B";
if '15:00:00'T <timepart(wagerdatetime) <='21:00:00'T then timeslot="C";
if '21:00:00'T <timepart(wagerdatetime) <='3:00:00'T then timeslot="D";
run;
I used
if '21:00:00'T <timepart(wagerdatetime) <='23:59:59'T then timeslot="D";
if '00:00:00'T =<timepart(wagerdatetime) <='3:00:00'T then timeslot="D";
run;
but I still have 3 with timeslot missing:
08JUN14:00:00:00
26JUN14:23:59:59
12MAY14:00:00:00
all others are fine.
Or replace '23:59:59'T in the IF condition by '24:00:00'T in order to close the 1-second gap between 23:59:59 and 00:00:00.
Hi,
if <condition> then;
else if <conition> then;
else;
So someting like:
if '3:00:00'T <timepart(wagerdatetime) <='9:00:00'T then timeslot="A"; else if '9:00:00'T <timepart(wagerdatetime) <='15:00:00'T then timeslot="B"; else if '15:00:00'T <timepart(wagerdatetime) <='21:00:00'T then timeslot="C"; else timeslot="D";run;
if '3:00:00'T <timepart(wagerdatetime) <='9:00:00'T then timeslot="A";
else if '9:00:00'T <timepart(wagerdatetime) <='15:00:00'T then timeslot="B";
else if '15:00:00'T <timepart(wagerdatetime) <='21:00:00'T then timeslot="C";
else if '21:00:00'T <timepart(wagerdatetime) <='23:59:59'T then timeslot="D";
else if '00:00:00'T =<timepart(wagerdatetime) <='3:00:00'T then timeslot="D";
run;
still got the three with timeslot missing
08JUN14:00:00:00
26JUN14:23:59:59
12MAY14:00:00:00
Or replace '23:59:59'T in the IF condition by '24:00:00'T in order to close the 1-second gap between 23:59:59 and 00:00:00.
If you look at my code, the final part 4 one is:
else timeslot="D";
I.e. if it doesn't fit into the other three then it is D, you don't need the final conditional, it can only be 1, 2, 3 or else D.
@RW9 I did not see your code earlier. Sorry. Actually using else is a better/simpler way.
I guess the "quick reply" inserted your post on the top but I was looking at bottom, so I missed your good suggestion.
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.