<?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: Sum based on date range in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-data-with-sorted-dates/m-p/400450#M97082</link>
    <description>&lt;P&gt;Your dates look like they are character variables. If so you likely want to create new variable that are SAS date valued numeric to use "range" of dates.&lt;/P&gt;
&lt;P&gt;What specific range of dates do you need? You don't mention it. Also you picture of the data does not include a variable named concent_cnt&amp;nbsp; so saying anything about that variable isn't much help.&lt;/P&gt;</description>
    <pubDate>Mon, 02 Oct 2017 20:33:38 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-10-02T20:33:38Z</dc:date>
    <item>
      <title>Sum of data with sorted dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-data-with-sorted-dates/m-p/400444#M97078</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled picture.png" style="width: 531px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15555i45165CCC3AE23891/image-size/large?v=v2&amp;amp;px=999" role="button" title="Untitled picture.png" alt="Untitled picture.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I am trying to sum units based on the start_dt where concent_cnt is 1 to 5&amp;nbsp;&lt;/P&gt;&lt;P&gt;i need a sum of units based on range of dates&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2017 21:43:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-data-with-sorted-dates/m-p/400444#M97078</guid>
      <dc:creator>hk2013</dc:creator>
      <dc:date>2017-10-02T21:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: Sum based on date range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-data-with-sorted-dates/m-p/400450#M97082</link>
      <description>&lt;P&gt;Your dates look like they are character variables. If so you likely want to create new variable that are SAS date valued numeric to use "range" of dates.&lt;/P&gt;
&lt;P&gt;What specific range of dates do you need? You don't mention it. Also you picture of the data does not include a variable named concent_cnt&amp;nbsp; so saying anything about that variable isn't much help.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2017 20:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-data-with-sorted-dates/m-p/400450#M97082</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-02T20:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: Sum based on date range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-data-with-sorted-dates/m-p/400452#M97083</link>
      <description>&lt;P&gt;its actually consec_cnt (which is counting 5 consecutive days)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i do have a range of five days but when i sum the units it sums all the units but i want sum of units for specific dates&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL ;&lt;BR /&gt;CREATE TABLE NEW AS&lt;BR /&gt;SELECT NP_RESOURCE_ID, category, START_DT, ACTDATE As End_DT, CONSEC_CNT,&lt;BR /&gt;INTCK('day',START_DT, ACTDATE) as DAY_DIFFERENCE&lt;BR /&gt;FROM cosick1&lt;BR /&gt;WHERE CONSEC_CNT &amp;gt;= 5&lt;BR /&gt;ORDER BY NP_RESOURCE_ID, ACTDATE ;&lt;BR /&gt;QUIT&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled picture.png" style="width: 551px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15556i531EA53E98F90B8C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Untitled picture.png" alt="Untitled picture.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2017 20:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-data-with-sorted-dates/m-p/400452#M97083</guid>
      <dc:creator>hk2013</dc:creator>
      <dc:date>2017-10-02T20:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Sum based on date range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-data-with-sorted-dates/m-p/400462#M97086</link>
      <description>&lt;P&gt;Basically you need GROUP BY, not ORDER BY:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select np_resource_id,start_dt,activity_dt as end_dt,
         sum(unit) as total_units,
         max(consec_cnt) as final_consec,
	 end_dt-start_dt as difference
  from have
  group by np_resource_id,start_dt
  having consec_cnt=final_consec and final_consec &amp;gt;=5;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will produce one record per np_resource_id/start_dt combination, but just those with a maximum consec_cnt&amp;gt;=5.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The program assumes for there are no "holes" in consec_cnt.&amp;nbsp; I.e. if there is a consec_cnt=6, there must also be a 1,2,3,4, and 5.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2017 21:23:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-data-with-sorted-dates/m-p/400462#M97086</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-10-02T21:23:44Z</dc:date>
    </item>
  </channel>
</rss>

