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.
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.
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.
What would the "PROC SUMMARY" look like?
There are examples in the PROC SUMMARY documentation. Give it a try.
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.
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;
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.
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 25. Read more here about why you should contribute and what is in it for you!
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.