You need to provide more information, specifically the code you ran, the log and what isn't working.
What part of this is unclear?
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;
I added "<" next to all the slashes, but the same problem persisted.
You never fixed the intervals. See my earlier response, which may not have been that clear, also below. Notice that ending goes to 00, not to 59. When it goes to 59, values such as 12:59.45 don't get grouped anywhere because it's not included in any of your ranges. So you need to change the ends to be the same as the beginning of the next interval AND use the exclude option to exclude it. Or put them the same and let SAS figure it out, I think the default is what you want. See the section in red below.
2019-07-03 04:16 PM
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;
@Reeza wrote:
I definitely don't need any more answers, feel free to mark Scott's answer as correct 🙂
Yeah @Rezza 's got 28K+ posts, I've got 653 🙂 Throw me a bone!
@lydiawawa , glad your problem is solved. I revisited your original post:
I have a time variable in the format of datetime32.4(ex: 21MAR2019:10:19:15.2970)
Beware of fractional seconds falling through the "gaps" in the format. You may need to truncate the fractional seconds from your data then apply the format, or else expand the format ranges to include the granularity of your source data.
Edit: Actually, the only gap is for 23:59:59, since all the other end points use the -< operator. If you're worried about fractional seconds, perhaps change "23:59:59"t to "23:59:59.999999"t (and test!)
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: