title: Averages in SAS with dates using months
body: <p>Let's say I have 50 years of data for each day and month. I also have a column which lists the max rainfall for each day of that dataset. I want to be able to compute the <strong>average monthly rainfall and standard deviation</strong> for each of those 50 years. How would I accomplish this task? I've considered using PROC MEANS:</p>
  
  <pre><code>PROC MEANS DATA = WORK.rainfall;
  BY DATE;
  VAR AVG(max_rainfall);
  RUN;
  </code></pre>
  
  <p>but I'm unfamiliar on how to let SAS understand that I want to be using the MM of the MMDDYY format to indicate where to start and stop calculating those averages for each month. I also do not know how I can tell SAS within this PROC MEANS statement on how to <strong>format the data correctly</strong>, using MMDDYY10. This is why my code fails. </p>
  
  <p>Update: I've also tried using this statement,</p>
  
  <pre><code>proc sql;
  create table new as
   select date,count(max_rainfall) as rainfall
    from WORK.rainfall 
    group by date;
  
  create table average as
   select year(date) as year,month(date) as month,avg(rainfall) as avg
    from new
     group by year,month;
  
    quit;
  </code></pre>
  
  <p>but that doesnt solve the problem either, unfortunately. It gives me the wrong values, although it does create a table. Where in my code could I have gone wrong? Am I telling SAS correctly that add all the rainfall's in 30 days and then divide it by the number of days for each month? Here's a snippet of my table. </p>
  
  <p><a href="https://i.stack.imgur.com/bJegF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bJegF.png" alt="enter image description here"></a></p>