Hi All,
I have a time variable in the format of datetime32.4(ex: 21MAR2019:10:19:15.2970) and I'm trying to group the time into the following block such as showing in the SAS code:
proc format;
value timerng
"06:00"t -< "15:59"t= "6:00am - 3:59pm"
"16:00"t -< "21:59"t = "4:00pm - 9:59pm"
"22:00"t -< "05:59"t = "10:00pm - 5:59am";
run;
I received an error message saying the start is greater than the end. Is there any other way to group the time variable into the wanted blocks?
Thank you!
Review this and tell us which observation numbers are incorrect:
data have;
do time="00:00:00"t to "23:59:59"t;
output;
end;
format time time.;
run;
proc format;
value timerng
"06:00:00"t -< "16:00:00"t = "6:00am - 3:59pm: Daytime"
"16:00:00"t -< "22:00:00"t = "4:00pm - 9:59pm: Evening"
"22:00:00"t - "23:59:59"t,
"00:00:00"t -< "06:00:00"t = "10:00pm - 5:59am: Overnight";
run;
data want;
set have;
time2=put(time,timerng.);
run;
"22:00"t -< "05:59"t = "10:00pm - 5:59am"
This is the problem, you can't have 05:59 is the high end of the range because it is less than 22:00
Perhaps what you want is:
proc format;
...
"22:00"t-"23:59"t, "00:00"t-"05:59"t = "10:00 pm - 5:59 am";
run;
Show us the code.
Show us sample data.
For some reason the following format does not cover the end point:
proc format;
value timerng
"06:00"t - "15:59"t= "6:00am - 3:59pm: Daytime"
"16:00"t - "21:59"t= "4:00pm - 9:59pm: Evening"
"22:00"t - "23:59"t, "00:00"t - "05:59"t, = "10:00pm - 5:59am: Overnight";
run;
When I do a freq count entries with time equal to 15:59 or 21:59 are all not converted to the categorical group. Does anyone know what is the cause?
This is what I have in return for 9:59pm: 7919.5840001106
+1 for the -< operand in proc format
Didn't work is vague and could mean anything from doesn't tell us if your computer disintegrated into bits or if you forgot a semicolon.
You need to provide more information, specifically the code you ran, the log and what isn't working.
@lydiawawa wrote:
Sorry this still did not work.. but I created a conditional statement after dividing time variable into min and second.
@Reeza wrote:
Didn't work is vague and could mean anything from doesn't tell us if your computer disintegrated into bits or if you forgot a semicolon.
You need to provide more information, specifically the code you ran, the log and what isn't working.
Classic reply @Reeza 🙂 🙂 🙂 Couldn't stop laughing. Plus it's spot on (but still funny). Wish I could give this 10 likes.
@Reeza wrote:
It's not intended to be mean, and I hope it doesn't come across that way, just that it's such a vague statement that conveys no information.
No it didn't come across as mean to me, and I hope not to @lydiawawa as well. I just thought your examples of vagueness, such as the computer disintegrating to bits, as funny. Perhaps that's just my sense of humor.
I wonder how you'd post an example of that? Take a picture and attach it I suppose 😉
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.