<?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 from bottom to top in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-from-bottom-to-top/m-p/461640#M117464</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/112309"&gt;@kmj636&lt;/a&gt;&amp;nbsp; &lt;EM&gt;You wrote -"Thanks again - the SAS community people are the best"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We the community(you included) are a team we are the best. It's fun to be here. I like the slogan "ask, find and share" by our managers&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp;et al. I am glad to be so active here that indirectly made my fellow class mates at my university use SAS&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 11 May 2018 17:49:36 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-05-11T17:49:36Z</dc:date>
    <item>
      <title>Sum from bottom to top</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-from-bottom-to-top/m-p/461602#M117443</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working with a SAS dataset and am creating new variables based on previous VARs. I would like to create a new VAR which holds the sums of another column based on the following: 10 obs,&lt;/P&gt;&lt;P&gt;#10 of the NewVar=#10 of OldVar&lt;/P&gt;&lt;P&gt;#9 of NVar= #9+#10 OVar&lt;/P&gt;&lt;P&gt;#8 NVar=#8+#9+#10 OVar ....&lt;/P&gt;&lt;P&gt;and so on.&lt;/P&gt;&lt;P&gt;So the total sum of the column will actually be Obs 1 of the New Var. Does anyone know how to sum backwards. I have been trying to wrap my head around this without changing the sort of the set or exporting and I would like to be able to do this by calling Vars rather than using the actual numbers to calculate, so I can use this in the future quickly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any help and suggestions you might have!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 May 2018 16:31:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-from-bottom-to-top/m-p/461602#M117443</guid>
      <dc:creator>kmj636</dc:creator>
      <dc:date>2018-05-11T16:31:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sum from bottom to top</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-from-bottom-to-top/m-p/461604#M117445</link>
      <description>&lt;P&gt;Please provide a sample data of what you have and what you want . Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 11 May 2018 16:33:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-from-bottom-to-top/m-p/461604#M117445</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-11T16:33:08Z</dc:date>
    </item>
    <item>
      <title>Re: Sum from bottom to top</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-from-bottom-to-top/m-p/461609#M117447</link>
      <description>&lt;P&gt;OVar&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NVar&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 55&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 54&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;52&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 49&lt;/P&gt;&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;45 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40&lt;/P&gt;&lt;P&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 34&lt;/P&gt;&lt;P&gt;8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 27&lt;/P&gt;&lt;P&gt;9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;19&lt;/P&gt;&lt;P&gt;10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;10&lt;/P&gt;</description>
      <pubDate>Fri, 11 May 2018 16:39:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-from-bottom-to-top/m-p/461609#M117447</guid>
      <dc:creator>kmj636</dc:creator>
      <dc:date>2018-05-11T16:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: Sum from bottom to top</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-from-bottom-to-top/m-p/461610#M117448</link>
      <description>&lt;P&gt;Here's an approach you can use.&amp;nbsp; Depending on the details of what you want, you should be able to tweak it as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First get the total for the next 10 observations.&amp;nbsp; Then cycle through the same observations and compute:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;newvar = 0;&lt;/P&gt;
&lt;P&gt;do k=1 to 10;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;newvar + oldvar;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;do k=1 to 10;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;newvar = newvar - oldvar;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since both SET statements operate independently of one another, both loops read exactly the same observations.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 May 2018 16:42:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-from-bottom-to-top/m-p/461610#M117448</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-05-11T16:42:29Z</dc:date>
    </item>
    <item>
      <title>Re: Sum from bottom to top</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-from-bottom-to-top/m-p/461615#M117451</link>
      <description>&lt;P&gt;You are awesome! Yes, I think I can get this to do what I want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for everyone's help and time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Enjoy your Friday!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 May 2018 16:47:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-from-bottom-to-top/m-p/461615#M117451</guid>
      <dc:creator>kmj636</dc:creator>
      <dc:date>2018-05-11T16:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: Sum from bottom to top</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-from-bottom-to-top/m-p/461618#M117454</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input OVar      NVar;
drop nvar;
cards;
1             55
2             54
3             52
4             49
5             45             
6             40
7             34
8             27
9             19
10           10
;

proc sql;
select sum(ovar) into :sum
from have;
quit;

data want;
set have;
retain nvar;
k=lag(ovar);
if _n_=1 then do;
nvar=&amp;amp;sum;
output;
end;
else do;
nvar=nvar-k;
output;
end;
drop k;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 May 2018 16:54:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-from-bottom-to-top/m-p/461618#M117454</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-11T16:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: Sum from bottom to top</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-from-bottom-to-top/m-p/461631#M117459</link>
      <description>&lt;P&gt;Thank you so much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just so everyone knows this worked a little better for me in my program then the post I accepted as the answer. The other one I could definitely tweak and works but this one was spot on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again - the SAS community people are the best&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 May 2018 17:29:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-from-bottom-to-top/m-p/461631#M117459</guid>
      <dc:creator>kmj636</dc:creator>
      <dc:date>2018-05-11T17:29:55Z</dc:date>
    </item>
    <item>
      <title>Re: Sum from bottom to top</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-from-bottom-to-top/m-p/461640#M117464</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/112309"&gt;@kmj636&lt;/a&gt;&amp;nbsp; &lt;EM&gt;You wrote -"Thanks again - the SAS community people are the best"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We the community(you included) are a team we are the best. It's fun to be here. I like the slogan "ask, find and share" by our managers&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp;et al. I am glad to be so active here that indirectly made my fellow class mates at my university use SAS&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 May 2018 17:49:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-from-bottom-to-top/m-p/461640#M117464</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-11T17:49:36Z</dc:date>
    </item>
  </channel>
</rss>

