Hi All,
I am looking for a way to make time groups from datetime values.
Further I have to summarize observations in these groups (time intervals).
The result must be like this:
Date, time | Interval time |
2017.10.25 6:40 | 6:00-7:00 |
2017.10.25 8:11 | 8:00-9:00 |
2017.10.25 10:27 | 10:00-11:00 |
2017.10.25 11:06 | 11:00-12:00 |
2017.10.25 12:53 | 12:00-13:00 |
2017.10.25 13:20 | 13:00-14:00 |
I tried this code:
data want;
set have;
interval=cats(put(hour(Date_time),2.),':00-',put(hour(Date_time)+1,2.),':00');
run;
It looks like this is very good for me but I don't know this is an appropriate solution or not.
I am a very beginner SAS programmer.
Thank you for your answers.
Looks fine for your required output. What I would say is that for further processing, i.e. checking if time is within those hours or what not, it would be a good idea to have a numeric upper and lower boundary, e.g.:
data want;
set have;
lower=hour(date_time);
upper=hour(date_time)+1;
interval=cats(put(lower,2.),':00-',put(upper,2.),':00');
run;
That way you can do comparisons on lower/upper and use the text for outputs.
Looks fine for your required output. What I would say is that for further processing, i.e. checking if time is within those hours or what not, it would be a good idea to have a numeric upper and lower boundary, e.g.:
data want;
set have;
lower=hour(date_time);
upper=hour(date_time)+1;
interval=cats(put(lower,2.),':00-',put(upper,2.),':00');
run;
That way you can do comparisons on lower/upper and use the text for outputs.
Thank you and i consider your suggestion.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.