BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
acloseCC
Fluorite | Level 6

I have been given the following data called P_sort: (small portion of it)
assoc_count  ...    time
5                           18JUL2017:23:59:59.0000000
9                           19JUL2017:02:59:59.0000000
2                           19JUL2017:05:59:59.0000000
1                           19JUL2017:08:59:59.0000000
2                           19JUL2017:11:59:59.0000000
1                           19JUL2017:14:59:59.0000000
4                           19JUL2017:17:59:59.0000000
9                           19JUL2017:20:59:59.0000000
10                         19JUL2017:23:59:59.0000000
15                         20JUL2017:02:59:59.0000000

...                          ...

 

I am tasked with finding an average of the assoc_count per hour over a specified number of weeks. This average will then be displayed with bar charts.

 

My current code is:

proc TIMESERIES data=P_sort out=P_sort;
   id time interval=hour
   accumulate=total
   start='018jul2018:00:00:00'dt
   end  ='025jul2018:00:00:00'dt;
   var assoc_count;
run;

/* AVERAGING GOES HERE*/

proc gchart data=P_sort;
	vbar time / sumvar=assoc_count maxis=axis1 raxis=axis2;
run;

 I don't know how to implement this. Any suggestions would be helpful.

1 ACCEPTED SOLUTION

Accepted Solutions
acloseCC
Fluorite | Level 6

My final solution is:

 

DATA P_sort;
	set L***;
	hour = hour(time);
run;

proc sql;
	create table selected_P_sort as
	select assoc_count, hour 
	from P_sort
	where datepart(time) between '01APR2018'd and '15APR2018'd AND hour between 7 and 23;
quit;

proc summary data=selected_P_sort;
	var assoc_count;
	class hour;
	output out=fin_P_sort MEAN=;
run;

 Thanks PaigeMiller and SASKiwi.

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

In a data step, compute the hour of the data.

 

hour = hour(datepart(time));

Then, run PROC SUMMARY on this data set to compute the averages by hour.

--
Paige Miller
acloseCC
Fluorite | Level 6

What would the "PROC SUMMARY" look like?

PaigeMiller
Diamond | Level 26

There are examples in the PROC SUMMARY documentation. Give it a try. 

--
Paige Miller
acloseCC
Fluorite | Level 6

When I use the following code, hour in the table does not change (stays at 185).

DATA P_sort;
	set LIB.W_W_HOURLY;
	hour = hour(datepart(time));
run;

How can this be fixed? I apologize for my limited knowledge of SAS. 

SASKiwi
PROC Star

Using DATEPART isn't necessary and it will give you the wrong answer. I think you can use it directly like this:

DATA P_sort;
	set LIB.W_W_HOURLY;
	hour = hour(time);
run;
acloseCC
Fluorite | Level 6

My final solution is:

 

DATA P_sort;
	set L***;
	hour = hour(time);
run;

proc sql;
	create table selected_P_sort as
	select assoc_count, hour 
	from P_sort
	where datepart(time) between '01APR2018'd and '15APR2018'd AND hour between 7 and 23;
quit;

proc summary data=selected_P_sort;
	var assoc_count;
	class hour;
	output out=fin_P_sort MEAN=;
run;

 Thanks PaigeMiller and SASKiwi.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 1257 views
  • 0 likes
  • 3 in conversation