@MLKohrman0321 wrote:
Hello,
I am working on my first big SAS project as part of my Capstone and I am completely stuck on how to get this complex data sorted. The data is daily readings of precipitation and temperature (min, mean, max) by day from over 90 weather stations (stationID). I have assigned each date into a CDC week (week 1,2,3, etc), but this data spans 12 years so there are 12 "Week 18's" for example.
I need to know how to generate a new tab for average precipitation, and then tell SAS to give me the average precipitation for each station by week by year (ie, station akr02 for each week in 2004, each week in 2005, etc).
A large number of complexities involving date type data is trying to use non-date valued variables. SAS date valued variables can display or group data using formats.
An brief example:
data example;
do datevalue = '01Jan2017'd to '30Apr2017'd;
y= 10*rand('uniform');
output;
end;
run;
proc format library=work;
picture yearwk (default=7)
low-high ='%Y-%U' (datatype=date)
;
run;
proc means data=example min max sum;
class datevalue;
format datevalue yearwk.;
var y ;
run;
The %U directive is one of three ways to define week that involves start day and how to consider which year a boundary value may have. Others are %V and %W (case sensitive). If you want a leading 0 in the week number then use %0U, %0V or %0W.
Use of %G instead of %Y also affects week assignment for year boundaries.
So having a DATE value often simplifies grouping for summaries and display at the same time.
... View more