<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Creating multiple sums of a variable with overlapping time periods in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-sums-of-a-variable-with-overlapping-time/m-p/432850#M281810</link>
    <description>&lt;P&gt;What are the rules for the overlapping periods? This sounds like a moving sum?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, using an approach as outlined here is likely a better method:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/25/027.html" target="_blank"&gt;http://support.sas.com/kb/25/027.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're also likely better off using a format to create your date ranges, than many if/then statements.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/190522"&gt;@CalebN&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello, I'm new to sas using the university edition&amp;nbsp; and having trouble getting multiple sums of a variable. I have rainfall data from 1975 to the present with each day a numeric day of the year (365 or 366 if it's a leap year). I want to make sums of many overlapping time periods. See my code below for what I've tried.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data rainfallsummary;&lt;BR /&gt;set work.import;&lt;BR /&gt;*this determines leap year;&lt;BR /&gt;if (mod(year,4)=0 and(mod(year,100) ne 0 or(mod(year,100)=0 and (mod(year,400)=0)))) then leap=1; else leap=0;&lt;BR /&gt;*may;&lt;BR /&gt;if ((leap=0) and ((day&amp;gt;=121)and (day&amp;lt;=151)) )then month=5;&lt;BR /&gt;if ((leap=1) and ((day&amp;gt;=122)and (day&amp;lt;=152)) )then month=5;&lt;BR /&gt;*june;&lt;BR /&gt;if ((leap=0) and ((day&amp;gt;=152)and (day&amp;lt;=181)) )then month=6;&lt;BR /&gt;if ((leap=1) and ((day&amp;gt;=153)and (day&amp;lt;=182)) )then month=6;&lt;BR /&gt;*july;&lt;BR /&gt;if ((leap=0) and ((day&amp;gt;=182)and (day&amp;lt;=212)) )then month=7;&lt;BR /&gt;if ((leap=1) and ((day&amp;gt;=183)and (day&amp;lt;=213)) )then month=7;&lt;BR /&gt;*august;&lt;BR /&gt;if ((leap=0) and ((day&amp;gt;=213)and (day&amp;lt;=243)) )then month=8;&lt;BR /&gt;if ((leap=1) and ((day&amp;gt;=214)and (day&amp;lt;=244)) )then month=8;&lt;BR /&gt;*june 15 to july 15;&lt;BR /&gt;*if ((leap=0) and ((day&amp;gt;=166)and (day&amp;lt;=196)) )then month=6.5;&lt;BR /&gt;*if ((leap=1) and ((day&amp;gt;=167)and (day&amp;lt;=197)) )then month=6.5;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc means data=rainfallsummary;&lt;BR /&gt;class year month;&lt;BR /&gt;var rain;&lt;BR /&gt;output out=work.rainTotals sum=sum;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to be able to get the sum of the rain during days 166 to 196 but this doesn't work with my code since I have more than one "month" for days 166 to 196.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any way to solve this?&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jan 2018 17:39:25 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-01-31T17:39:25Z</dc:date>
    <item>
      <title>Creating multiple sums of a variable with overlapping time periods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-sums-of-a-variable-with-overlapping-time/m-p/432848#M281809</link>
      <description>&lt;P&gt;Hello, I'm new to sas using the university edition&amp;nbsp; and having trouble getting multiple sums of a variable. I have rainfall data from 1975 to the present with each day a numeric day of the year (365 or 366 if it's a leap year). I want to make sums of many overlapping time periods. See my code below for what I've tried.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data rainfallsummary;&lt;BR /&gt;set work.import;&lt;BR /&gt;*this determines leap year;&lt;BR /&gt;if (mod(year,4)=0 and(mod(year,100) ne 0 or(mod(year,100)=0 and (mod(year,400)=0)))) then leap=1; else leap=0;&lt;BR /&gt;*may;&lt;BR /&gt;if ((leap=0) and ((day&amp;gt;=121)and (day&amp;lt;=151)) )then month=5;&lt;BR /&gt;if ((leap=1) and ((day&amp;gt;=122)and (day&amp;lt;=152)) )then month=5;&lt;BR /&gt;*june;&lt;BR /&gt;if ((leap=0) and ((day&amp;gt;=152)and (day&amp;lt;=181)) )then month=6;&lt;BR /&gt;if ((leap=1) and ((day&amp;gt;=153)and (day&amp;lt;=182)) )then month=6;&lt;BR /&gt;*july;&lt;BR /&gt;if ((leap=0) and ((day&amp;gt;=182)and (day&amp;lt;=212)) )then month=7;&lt;BR /&gt;if ((leap=1) and ((day&amp;gt;=183)and (day&amp;lt;=213)) )then month=7;&lt;BR /&gt;*august;&lt;BR /&gt;if ((leap=0) and ((day&amp;gt;=213)and (day&amp;lt;=243)) )then month=8;&lt;BR /&gt;if ((leap=1) and ((day&amp;gt;=214)and (day&amp;lt;=244)) )then month=8;&lt;BR /&gt;*june 15 to july 15;&lt;BR /&gt;*if ((leap=0) and ((day&amp;gt;=166)and (day&amp;lt;=196)) )then month=6.5;&lt;BR /&gt;*if ((leap=1) and ((day&amp;gt;=167)and (day&amp;lt;=197)) )then month=6.5;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc means data=rainfallsummary;&lt;BR /&gt;class year month;&lt;BR /&gt;var rain;&lt;BR /&gt;output out=work.rainTotals sum=sum;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to be able to get the sum of the rain during days 166 to 196 but this doesn't work with my code since I have more than one "month" for days 166 to 196.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way to solve this?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 17:35:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-sums-of-a-variable-with-overlapping-time/m-p/432848#M281809</guid>
      <dc:creator>CalebN</dc:creator>
      <dc:date>2018-01-31T17:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple sums of a variable with overlapping time periods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-sums-of-a-variable-with-overlapping-time/m-p/432850#M281810</link>
      <description>&lt;P&gt;What are the rules for the overlapping periods? This sounds like a moving sum?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, using an approach as outlined here is likely a better method:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/25/027.html" target="_blank"&gt;http://support.sas.com/kb/25/027.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're also likely better off using a format to create your date ranges, than many if/then statements.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/190522"&gt;@CalebN&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello, I'm new to sas using the university edition&amp;nbsp; and having trouble getting multiple sums of a variable. I have rainfall data from 1975 to the present with each day a numeric day of the year (365 or 366 if it's a leap year). I want to make sums of many overlapping time periods. See my code below for what I've tried.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data rainfallsummary;&lt;BR /&gt;set work.import;&lt;BR /&gt;*this determines leap year;&lt;BR /&gt;if (mod(year,4)=0 and(mod(year,100) ne 0 or(mod(year,100)=0 and (mod(year,400)=0)))) then leap=1; else leap=0;&lt;BR /&gt;*may;&lt;BR /&gt;if ((leap=0) and ((day&amp;gt;=121)and (day&amp;lt;=151)) )then month=5;&lt;BR /&gt;if ((leap=1) and ((day&amp;gt;=122)and (day&amp;lt;=152)) )then month=5;&lt;BR /&gt;*june;&lt;BR /&gt;if ((leap=0) and ((day&amp;gt;=152)and (day&amp;lt;=181)) )then month=6;&lt;BR /&gt;if ((leap=1) and ((day&amp;gt;=153)and (day&amp;lt;=182)) )then month=6;&lt;BR /&gt;*july;&lt;BR /&gt;if ((leap=0) and ((day&amp;gt;=182)and (day&amp;lt;=212)) )then month=7;&lt;BR /&gt;if ((leap=1) and ((day&amp;gt;=183)and (day&amp;lt;=213)) )then month=7;&lt;BR /&gt;*august;&lt;BR /&gt;if ((leap=0) and ((day&amp;gt;=213)and (day&amp;lt;=243)) )then month=8;&lt;BR /&gt;if ((leap=1) and ((day&amp;gt;=214)and (day&amp;lt;=244)) )then month=8;&lt;BR /&gt;*june 15 to july 15;&lt;BR /&gt;*if ((leap=0) and ((day&amp;gt;=166)and (day&amp;lt;=196)) )then month=6.5;&lt;BR /&gt;*if ((leap=1) and ((day&amp;gt;=167)and (day&amp;lt;=197)) )then month=6.5;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc means data=rainfallsummary;&lt;BR /&gt;class year month;&lt;BR /&gt;var rain;&lt;BR /&gt;output out=work.rainTotals sum=sum;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to be able to get the sum of the rain during days 166 to 196 but this doesn't work with my code since I have more than one "month" for days 166 to 196.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any way to solve this?&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 17:39:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-sums-of-a-variable-with-overlapping-time/m-p/432850#M281810</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-31T17:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple sums of a variable with overlapping time periods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-sums-of-a-variable-with-overlapping-time/m-p/432893#M281811</link>
      <description>&lt;P&gt;If you just want to get the sum of the rain during days 166 to 196 per month per year, add where statement in Proce means procedure as:&lt;/P&gt;&lt;P&gt;where 166&amp;lt;=day&amp;lt;=196;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Otherwise, please provide an example output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 20:11:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-sums-of-a-variable-with-overlapping-time/m-p/432893#M281811</guid>
      <dc:creator>MINX</dc:creator>
      <dc:date>2018-01-31T20:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple sums of a variable with overlapping time periods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-sums-of-a-variable-with-overlapping-time/m-p/432895#M281812</link>
      <description>&lt;P&gt;Sums of many overlapping groupings can be done using a Multilabel format, and then running the data through PROC MEANS or PROC SUMMARY. An example of multilabel formats are shown here:&amp;nbsp;&lt;A href="http://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=proc&amp;amp;docsetTarget=p1upn25lbfo6mkn1wncu4dyh9q91.htm&amp;amp;locale=en#n0h1r41mckp14dn1a02y5utzrcet" target="_blank"&gt;http://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=proc&amp;amp;docsetTarget=p1upn25lbfo6mkn1wncu4dyh9q91.htm&amp;amp;locale=en#n0h1r41mckp14dn1a02y5utzrcet&lt;/A&gt; which seems to meet your needs as stated in your original post.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 20:15:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-sums-of-a-variable-with-overlapping-time/m-p/432895#M281812</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-01-31T20:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple sums of a variable with overlapping time periods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-sums-of-a-variable-with-overlapping-time/m-p/432911#M281813</link>
      <description>&lt;P&gt;I would suggest using day and year to create a SAS date value and then manipulate from there with date functions and or formats.&lt;/P&gt;
&lt;P&gt;You do not mention anything about your range of years but a custom multilabel format could be made to make the correct group:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data work.example;
   input year day rain;
   date= datejul(year*1000+day);
   format date date9.;
   Month=month(date);
datalines;
2016 1   1
2016 59  2
2016 60  3
2016 61  4
2016 123  5
2016 155  .4
2016 168  .3
2017 1    .4
2017 59   .5
2017 60   .6
2017 61   .7
2017 123  .8
2017 155  .4
2017 167  .3
;
run;


proc format library=work;
value custmonth (multilabel notsorted)
'01Jan2016'd - '31DEC2016'd = [year8.]
'01Jan2016'd - '31DEC2016'd = [mmyy8.]
'16JUN2016'd - '30Jun2016'd = '6.5M2016'
'01Jan2017'd - '31DEC2017'd = [year8.]
'01Jan2017'd - '31DEC2017'd = [mmyy8.]
'16JUN2017'd - '30Jun2017'd = '6.5M2017'
;
run;

proc means data=work.example;
   class date /mlf;
   format date custmonth. ;
   var rain;
   output out=work.exampletotals sum=sum;
run;
proc sort data=work.exampletotals;
by date;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Jan 2018 21:02:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-sums-of-a-variable-with-overlapping-time/m-p/432911#M281813</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-31T21:02:14Z</dc:date>
    </item>
  </channel>
</rss>

