<?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 SUm By Dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SUm-By-Dates/m-p/18718#M2835</link>
    <description>i have &lt;BR /&gt;
&lt;BR /&gt;
data report;&lt;BR /&gt;
input dat tran;&lt;BR /&gt;
format dat mmddyy8.;&lt;BR /&gt;
cards;&lt;BR /&gt;
10/12/98 45&lt;BR /&gt;
10/16/98 66&lt;BR /&gt;
10/26/98 23&lt;BR /&gt;
11/06/00 89&lt;BR /&gt;
11/20/00 75&lt;BR /&gt;
11/23/00 45&lt;BR /&gt;
11/29/00 63&lt;BR /&gt;
&lt;BR /&gt;
Now i want the sum of tran between 10/12/98 to 10/16/98, and i want the sum of tran from 11/06/00 to 11/23/00 in to a new variable Tot.if the trans is not between the mentioned dates it should remain same .&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
output shd be &lt;BR /&gt;
&lt;BR /&gt;
 dat     tran    Total&lt;BR /&gt;
10/12/98   45      -&lt;BR /&gt;
10/16/98  66     101&lt;BR /&gt;
10/26/98  23      23&lt;BR /&gt;
11/06/00  89      -&lt;BR /&gt;
11/20/00  75      -&lt;BR /&gt;
11/23/00  45     203&lt;BR /&gt;
11/29/00  63      63&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Main&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Main

Message was edited by: Main</description>
    <pubDate>Wed, 15 Apr 2009 06:06:45 GMT</pubDate>
    <dc:creator>R_Win</dc:creator>
    <dc:date>2009-04-15T06:06:45Z</dc:date>
    <item>
      <title>SUm By Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUm-By-Dates/m-p/18718#M2835</link>
      <description>i have &lt;BR /&gt;
&lt;BR /&gt;
data report;&lt;BR /&gt;
input dat tran;&lt;BR /&gt;
format dat mmddyy8.;&lt;BR /&gt;
cards;&lt;BR /&gt;
10/12/98 45&lt;BR /&gt;
10/16/98 66&lt;BR /&gt;
10/26/98 23&lt;BR /&gt;
11/06/00 89&lt;BR /&gt;
11/20/00 75&lt;BR /&gt;
11/23/00 45&lt;BR /&gt;
11/29/00 63&lt;BR /&gt;
&lt;BR /&gt;
Now i want the sum of tran between 10/12/98 to 10/16/98, and i want the sum of tran from 11/06/00 to 11/23/00 in to a new variable Tot.if the trans is not between the mentioned dates it should remain same .&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
output shd be &lt;BR /&gt;
&lt;BR /&gt;
 dat     tran    Total&lt;BR /&gt;
10/12/98   45      -&lt;BR /&gt;
10/16/98  66     101&lt;BR /&gt;
10/26/98  23      23&lt;BR /&gt;
11/06/00  89      -&lt;BR /&gt;
11/20/00  75      -&lt;BR /&gt;
11/23/00  45     203&lt;BR /&gt;
11/29/00  63      63&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Main&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Main

Message was edited by: Main</description>
      <pubDate>Wed, 15 Apr 2009 06:06:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUm-By-Dates/m-p/18718#M2835</guid>
      <dc:creator>R_Win</dc:creator>
      <dc:date>2009-04-15T06:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: SUm By Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUm-By-Dates/m-p/18719#M2836</link>
      <description>My editing didn't work.  I'll try reposting

Message was edited by: 1162</description>
      <pubDate>Wed, 15 Apr 2009 13:35:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUm-By-Dates/m-p/18719#M2836</guid>
      <dc:creator>1162</dc:creator>
      <dc:date>2009-04-15T13:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: SUm By Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUm-By-Dates/m-p/18720#M2837</link>
      <description>Well, this isn't very elegant, but it produces the output you're looking for.  In order to run this, you have to hard code each date range (and increment the Period by 1) in a table called ranges.  After that, I think it's pretty automatic.&lt;BR /&gt;
&lt;BR /&gt;
[pre]data report;&lt;BR /&gt;
input dat mmddyy8. tran;&lt;BR /&gt;
format dat mmddyy8.;&lt;BR /&gt;
cards;&lt;BR /&gt;
10/12/98 45&lt;BR /&gt;
10/16/98 66&lt;BR /&gt;
10/26/98 23&lt;BR /&gt;
11/06/00 89&lt;BR /&gt;
11/20/00 75&lt;BR /&gt;
11/23/00 45&lt;BR /&gt;
11/29/00 63&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data ranges;&lt;BR /&gt;
	set report;&lt;BR /&gt;
	if '12Oct1998'd le dat le '16Oct1998'd then do; Period=1; output; end;&lt;BR /&gt;
	if '06Nov2000'd le dat le '23Nov2000'd then do; Period=2; output; end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
	create table sums as&lt;BR /&gt;
	select period, dat, max(dat) as End, case when dat=max(dat) then sum(tran) else . end as Total&lt;BR /&gt;
	from ranges&lt;BR /&gt;
	group by period&lt;BR /&gt;
	order by period, dat;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
data report (drop=period end);&lt;BR /&gt;
	merge report (in=a) sums (in=b);&lt;BR /&gt;
	by dat;&lt;BR /&gt;
	if a and not b then total=tran;&lt;BR /&gt;
run;[/pre]</description>
      <pubDate>Fri, 17 Apr 2009 21:13:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUm-By-Dates/m-p/18720#M2837</guid>
      <dc:creator>1162</dc:creator>
      <dc:date>2009-04-17T21:13:02Z</dc:date>
    </item>
  </channel>
</rss>

