<?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: Please help me out the Cumulative sum using first. condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Please-help-me-out-the-Cumulative-sum-using-first-condition/m-p/468924#M119832</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TEST;
INPUT ID$ CTR IS AS2;
CARDS;
AA 0 0 30
AA 2 3 30
AA 28 28 30
BB 10 5 22
BB 0 0 22
BB 12 4 22
;
RUN;
data want;
 set test;
 by id;
 if first.id then sum=as2;
  else sum+is;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 09 Jun 2018 10:04:33 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-06-09T10:04:33Z</dc:date>
    <item>
      <title>Please help me out the Cumulative sum using first. condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Please-help-me-out-the-Cumulative-sum-using-first-condition/m-p/468915#M119829</link>
      <description>&lt;P&gt;DATA TEST;&lt;BR /&gt;INPUT ID$ CTR IS AS2;&lt;BR /&gt;CARDS;&lt;BR /&gt;AA 0 0 30&lt;BR /&gt;AA 2 3 30&lt;BR /&gt;AA 28 28 30&lt;BR /&gt;BB 10 5 22&lt;BR /&gt;BB 0 0 22&lt;BR /&gt;BB 12 4 22&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OUTPUT:&lt;/P&gt;&lt;P&gt;ID CTR IS A2 A1&lt;BR /&gt;AA 0 7 30 30&lt;BR /&gt;AA 2 3 30 33&lt;BR /&gt;AA 28 28 30 61&lt;BR /&gt;BB 0 9 22 22&lt;BR /&gt;BB 0 3 22 22&lt;BR /&gt;BB 10 5 22 27&lt;BR /&gt;BB 12 4 22 31&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IF FIRST.ID THEN DO;&lt;/P&gt;&lt;P&gt;A1=A2&lt;/P&gt;&lt;P&gt;AND SAME LOOP IF CTR IS 0 THEN A1=A2 ELSE A1+IS(CUMULATIVE SUM)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jun 2018 07:13:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Please-help-me-out-the-Cumulative-sum-using-first-condition/m-p/468915#M119829</guid>
      <dc:creator>Bhargavi221</dc:creator>
      <dc:date>2018-06-09T07:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: Please help me out the Cumulative sum using first. condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Please-help-me-out-the-Cumulative-sum-using-first-condition/m-p/468924#M119832</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TEST;
INPUT ID$ CTR IS AS2;
CARDS;
AA 0 0 30
AA 2 3 30
AA 28 28 30
BB 10 5 22
BB 0 0 22
BB 12 4 22
;
RUN;
data want;
 set test;
 by id;
 if first.id then sum=as2;
  else sum+is;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Jun 2018 10:04:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Please-help-me-out-the-Cumulative-sum-using-first-condition/m-p/468924#M119832</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-06-09T10:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: Please help me out the Cumulative sum using first. condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Please-help-me-out-the-Cumulative-sum-using-first-condition/m-p/468928#M119833</link>
      <description>&lt;P&gt;Ksharp, Thank you so much for the update.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA TEST;&lt;BR /&gt;INPUT ID$ CTR IS AS2;&lt;BR /&gt;CARDS;&lt;BR /&gt;AA 0 0 30&lt;BR /&gt;AA 2 3 30&lt;BR /&gt;AA 28 28 30&lt;BR /&gt;BB 10 5 22&lt;BR /&gt;&lt;STRONG&gt;BB 0 6 22&lt;/STRONG&gt;&lt;BR /&gt;BB 12 4 22&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;This case your code is summing up to (BB 0 6 22 ) 28, but i need if CTR=0 Then sum= as2 (don't add IS to sum when CTR =0)&lt;/P&gt;&lt;P&gt;Like below:&lt;/P&gt;&lt;P&gt;ID CTR IS AS2 sum&lt;BR /&gt;AA 0 0 30 30&lt;BR /&gt;AA 2 3 30 33&lt;BR /&gt;AA 28 28 30 61&lt;BR /&gt;BB 10 5 22 22&lt;BR /&gt;BB 0 6 22 22&lt;BR /&gt;BB 12 4 22 26&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jun 2018 11:49:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Please-help-me-out-the-Cumulative-sum-using-first-condition/m-p/468928#M119833</guid>
      <dc:creator>Bhargavi221</dc:creator>
      <dc:date>2018-06-09T11:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: Please help me out the Cumulative sum using first. condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Please-help-me-out-the-Cumulative-sum-using-first-condition/m-p/468933#M119836</link>
      <description>&lt;P&gt;just a very&amp;nbsp;&lt;SPAN&gt;small tweak to Ksharp's code:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TEST;
INPUT ID$ CTR IS AS2;
CARDS;
AA 0 0 30
AA 2 3 30
AA 28 28 30
BB 10 5 22
BB 0 0 22
BB 12 4 22
;
RUN;


data want;
 set test;
 by id;
 if first.id or ctr=0 then  sum=as2;
  else   sum+is;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jun 2018 14:18:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Please-help-me-out-the-Cumulative-sum-using-first-condition/m-p/468933#M119836</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-09T14:18:20Z</dc:date>
    </item>
  </channel>
</rss>

