<?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: Summinng on first and last. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Summinng-on-first-and-last/m-p/39191#M10090</link>
    <description>in the o/p you have shown ,&lt;BR /&gt;
you are adding id and inco  where last=1.&lt;BR /&gt;
&lt;BR /&gt;
but you are saying "income sum betweeen where first=1 and last=1"&lt;BR /&gt;
here is solution.&lt;BR /&gt;
&lt;BR /&gt;
data i;&lt;BR /&gt;
input id inco first last;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 2 1 0&lt;BR /&gt;
1 2 0 0&lt;BR /&gt;
2 2 0 1&lt;BR /&gt;
3 4 1 0&lt;BR /&gt;
4 6 0 0&lt;BR /&gt;
5 7 0 1&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
data i1;&lt;BR /&gt;
set i;&lt;BR /&gt;
retain tot 0;&lt;BR /&gt;
if first=1 then tot = inco;&lt;BR /&gt;
else if last = 1 then final_tot = tot + inco;&lt;BR /&gt;
else  tot = tot + inco;&lt;BR /&gt;
drop tot;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
o/p - i1&lt;BR /&gt;
&lt;BR /&gt;
id inc first last final_tot&lt;BR /&gt;
1 2 1 0&lt;BR /&gt;
1 2 0 0&lt;BR /&gt;
2 2 0 1 6&lt;BR /&gt;
3 4 1 0&lt;BR /&gt;
4 6 0 0&lt;BR /&gt;
5 7 0 1 17</description>
    <pubDate>Mon, 01 Jun 2009 10:20:14 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-06-01T10:20:14Z</dc:date>
    <item>
      <title>Summinng on first and last.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summinng-on-first-and-last/m-p/39189#M10088</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
i have a data i want the income sum betweeen where first=1 and last=1;&lt;BR /&gt;
&lt;BR /&gt;
id inco  first last &lt;BR /&gt;
 1  2    1    0&lt;BR /&gt;
 1  2    0    0&lt;BR /&gt;
 2  2    0    1&lt;BR /&gt;
 3  4    1    0&lt;BR /&gt;
 4  6    0    0&lt;BR /&gt;
 5  7    0    1&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
the output is like this&lt;BR /&gt;
&lt;BR /&gt;
id inc first last  final_tot&lt;BR /&gt;
 1  2    1    0&lt;BR /&gt;
 1  2    0    0&lt;BR /&gt;
 2  2    0    1     4 &lt;BR /&gt;
 3  4    1    0&lt;BR /&gt;
 4  6    0    0&lt;BR /&gt;
 5  7    0    1     12</description>
      <pubDate>Mon, 01 Jun 2009 09:54:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summinng-on-first-and-last/m-p/39189#M10088</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-01T09:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: Summinng on first and last.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summinng-on-first-and-last/m-p/39190#M10089</link>
      <description>You should explore the use of BY group processing techniques in the data step such as FIRST. and LAST., together with RETAIN.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Mon, 01 Jun 2009 10:04:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summinng-on-first-and-last/m-p/39190#M10089</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2009-06-01T10:04:11Z</dc:date>
    </item>
    <item>
      <title>Re: Summinng on first and last.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summinng-on-first-and-last/m-p/39191#M10090</link>
      <description>in the o/p you have shown ,&lt;BR /&gt;
you are adding id and inco  where last=1.&lt;BR /&gt;
&lt;BR /&gt;
but you are saying "income sum betweeen where first=1 and last=1"&lt;BR /&gt;
here is solution.&lt;BR /&gt;
&lt;BR /&gt;
data i;&lt;BR /&gt;
input id inco first last;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 2 1 0&lt;BR /&gt;
1 2 0 0&lt;BR /&gt;
2 2 0 1&lt;BR /&gt;
3 4 1 0&lt;BR /&gt;
4 6 0 0&lt;BR /&gt;
5 7 0 1&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
data i1;&lt;BR /&gt;
set i;&lt;BR /&gt;
retain tot 0;&lt;BR /&gt;
if first=1 then tot = inco;&lt;BR /&gt;
else if last = 1 then final_tot = tot + inco;&lt;BR /&gt;
else  tot = tot + inco;&lt;BR /&gt;
drop tot;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
o/p - i1&lt;BR /&gt;
&lt;BR /&gt;
id inc first last final_tot&lt;BR /&gt;
1 2 1 0&lt;BR /&gt;
1 2 0 0&lt;BR /&gt;
2 2 0 1 6&lt;BR /&gt;
3 4 1 0&lt;BR /&gt;
4 6 0 0&lt;BR /&gt;
5 7 0 1 17</description>
      <pubDate>Mon, 01 Jun 2009 10:20:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summinng-on-first-and-last/m-p/39191#M10090</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-01T10:20:14Z</dc:date>
    </item>
  </channel>
</rss>

