Data have;
input Date:mmddyy10. time:time5. Count;
format date date9. time time5.;
cards;
5/11/2017 1:50 2
5/11/2017 2:30 3
5/11/2017 2:50 8
5/11/2017 1:10 4
;
proc sql;
create table want as select distinct hour(time) as hour, sum(count) as count from have group by hour(time);
quit;
data have;
input _date :ddmmyy10. time :time5. count;
date = _date * 86400 + time;
format date datetime19.;
drop _date time;
cards;
5/11/2017 1:50 2
5/11/2017 2:30 3
5/11/2017 2:50 8
5/11/2017 1:10 4
;
run;
data int;
set have;
hour = intnx('hour',date,0,'begin');
format hour datetime19.;
run;
proc summary data=int nway;
class hour;
var count;
output out=want (keep=hour count) sum(count)=count;
run;
proc print data=want noobs;
run;
Result:
hour count 05NOV2017:01:00:00 6 05NOV2017:02:00:00 11
I used datetime values because you never can be sure that you'll only deal with one day.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.