BookmarkSubscribeRSS Feed
srinivaschary
Calcite | Level 5
Hi,
I want create hour bocket FROM DDMMYY HH:MM:SS format can you please explain how to do
Data set
Date Count
5/11/2017 1:50 2
5/11/2017 2:30 3
5/11/2017 2:50 8
5/11/2017 1:10 4

Expected
Hour (Bucket) Count
1 6
2 11
2 REPLIES 2
Jagadishkatam
Amethyst | Level 16
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;

Thanks,
Jag
Kurt_Bremser
Super User
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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1471 views
  • 0 likes
  • 3 in conversation