<?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: accumulative sum with condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225480#M40476</link>
    <description>&lt;P&gt;Thank you so much PS stats! It works perfect!&lt;/P&gt;</description>
    <pubDate>Mon, 14 Sep 2015 21:58:52 GMT</pubDate>
    <dc:creator>last_one</dc:creator>
    <dc:date>2015-09-14T21:58:52Z</dc:date>
    <item>
      <title>accumulative sum with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225232#M40409</link>
      <description>&lt;P&gt;I am working on this daily report and try to find a way to get what I want. So here is the example:&lt;/P&gt;&lt;P&gt;If Today(the date I run SAS)&amp;nbsp;is Monday, Sep 7, 2015 , then I need the 'Want' column. The challenge part is&amp;nbsp;the &lt;SPAN&gt;Friday, September 04, 2015&lt;/SPAN&gt;'s want number, I need it to be the sum of Have column from Friday Sep 04 to Sunday Sep 06th.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to get it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;Date&lt;/TD&gt;&lt;TD&gt;Have&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Want&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Tuesday, September 01, 2015&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Wednesday, September 02, 2015&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Thursday, September 03, 2015&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Friday, September 04, 2015&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Saturday, September 05, 2015&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sunday, September 06, 2015&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2015 21:26:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225232#M40409</guid>
      <dc:creator>last_one</dc:creator>
      <dc:date>2015-09-11T21:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: accumulative sum with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225234#M40410</link>
      <description>How are you defining the rules? Is it just for this Week's data or all weeks? Are all Fridays only for the weekend?</description>
      <pubDate>Fri, 11 Sep 2015 21:52:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225234#M40410</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-09-11T21:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: accumulative sum with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225237#M40411</link>
      <description>&lt;P&gt;Here is one way to do this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date :yymmdd. have;
format date weekdate37.;
datalines;
2015-09-01 2
2015-09-02 3
2015-09-03 4
2015-09-04 5
2015-09-05 2
2015-09-06 5
;

proc sql;
create table Fridays as
select intnx("WEEK.6", date, 0) as date, sum(have) as want
from have 
where weekday(date) in (1,6,7)
group by calculated date;
quit;

data want;
merge have Fridays(in=friday);
by date;
if not friday then want = have;
if weekday(date) in (1, 7) then want = 0;
run;

proc print data=want; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Sep 2015 22:24:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225237#M40411</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-09-11T22:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: accumulative sum with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225238#M40412</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;, it is for all Fridays if the day I run SAS is on Monday.</description>
      <pubDate>Fri, 11 Sep 2015 22:34:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225238#M40412</guid>
      <dc:creator>last_one</dc:creator>
      <dc:date>2015-09-11T22:34:27Z</dc:date>
    </item>
    <item>
      <title>Re: accumulative sum with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225239#M40413</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;, thank you! I will try it when back to work on Monday.</description>
      <pubDate>Fri, 11 Sep 2015 22:42:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225239#M40413</guid>
      <dc:creator>last_one</dc:creator>
      <dc:date>2015-09-11T22:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: accumulative sum with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225284#M40422</link>
      <description>&lt;P&gt;&amp;nbsp;here is another way;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input date :yymmdd. have;&lt;BR /&gt;format date weekdate37.;&lt;BR /&gt;datalines;&lt;BR /&gt;2015-09-01 2&lt;BR /&gt;2015-09-02 3&lt;BR /&gt;2015-09-03 4&lt;BR /&gt;2015-09-04 5&lt;BR /&gt;2015-09-05 2&lt;BR /&gt;2015-09-06 5&lt;BR /&gt;;&lt;BR /&gt;proc sort; by descending date;&lt;/P&gt;
&lt;P&gt;data want; set have;&lt;BR /&gt;day=weekday(date); drop day sum;&lt;BR /&gt;want=have;&lt;BR /&gt;if weekday(date)=1 then do; sum+have; want=0; end; &amp;nbsp; &amp;nbsp; &amp;nbsp; *if &amp;nbsp; sunday;&lt;BR /&gt;if weekday(date)=7 then do; sum+have; want=0; end; &amp;nbsp; &amp;nbsp; &amp;nbsp; *if &amp;nbsp; saturday;&lt;BR /&gt;if weekday(date)=6 then do; sum+have; want=sum; sum=0; end;&amp;nbsp; *if&amp;nbsp;&amp;nbsp; friday;&lt;BR /&gt;proc sort; by date;&lt;BR /&gt;proc print; run;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Sep 2015 22:00:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225284#M40422</guid>
      <dc:creator>Jim_G</dc:creator>
      <dc:date>2015-09-12T22:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: accumulative sum with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225294#M40423</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/41031"&gt;@Jim_G﻿&lt;/a&gt;,&amp;nbsp;Nice and simple solution, as long as there are no holes in the time series. Try it, for example, with&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date :yymmdd. have;
format date weekdate37.;
datalines;
2015-09-01 2
2015-09-02 3
2015-09-03 4
2015-09-04 5
2015-09-05 2
2015-09-06 5
2015-09-12 2
2015-09-13 5
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 13 Sep 2015 01:36:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225294#M40423</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-09-13T01:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: accumulative sum with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225303#M40426</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;   I thought about a little error message if the days were not consecutive.</description>
      <pubDate>Sun, 13 Sep 2015 12:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225303#M40426</guid>
      <dc:creator>Jim_G</dc:creator>
      <dc:date>2015-09-13T12:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: accumulative sum with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225480#M40476</link>
      <description>&lt;P&gt;Thank you so much PS stats! It works perfect!&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 21:58:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/accumulative-sum-with-condition/m-p/225480#M40476</guid>
      <dc:creator>last_one</dc:creator>
      <dc:date>2015-09-14T21:58:52Z</dc:date>
    </item>
  </channel>
</rss>

