<?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 addition and subtraction in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/addition-and-subtraction/m-p/686297#M208214</link>
    <description>&lt;P&gt;I have a data set test as shown below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data test;&lt;BR /&gt;input brand $ loan;&lt;BR /&gt;datalines;&lt;BR /&gt;mini&amp;nbsp; &amp;nbsp; 100&lt;BR /&gt;mini&amp;nbsp; &amp;nbsp; &amp;nbsp;20&lt;BR /&gt;mini&amp;nbsp; &amp;nbsp; &amp;nbsp;30&lt;BR /&gt;toyota&amp;nbsp; 120&lt;BR /&gt;toyota&amp;nbsp; 10&lt;BR /&gt;toyota&amp;nbsp; 20&lt;BR /&gt;toyota&amp;nbsp; 12&lt;BR /&gt;toyota&amp;nbsp; 34&lt;BR /&gt;audi&amp;nbsp; &amp;nbsp;320&lt;BR /&gt;audi&amp;nbsp; &amp;nbsp;200&lt;BR /&gt;audi&amp;nbsp; &amp;nbsp;80&lt;BR /&gt;;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want output to be shown as&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;mini&amp;nbsp; &lt;STRONG&gt;70&lt;/STRONG&gt; (100 - 20 - 30 )&lt;BR /&gt;mini 20&lt;BR /&gt;mini 30&lt;BR /&gt;toyota&amp;nbsp; &lt;STRONG&gt;44&lt;/STRONG&gt; (120 - 10 - 20 - 12- 34)&lt;BR /&gt;toyota 10&lt;BR /&gt;toyota 20&lt;BR /&gt;toyota 12&lt;BR /&gt;toyota 34&lt;BR /&gt;audi&amp;nbsp; &lt;STRONG&gt;40&lt;/STRONG&gt;&amp;nbsp; (320 - 200 - 80)&lt;BR /&gt;audi 200&lt;BR /&gt;audi 80&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I only wanted to know how to come at those bold values.&lt;/P&gt;&lt;P&gt;Kindly help.&lt;/P&gt;&lt;P&gt;Thanks! in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 24 Sep 2020 08:15:00 GMT</pubDate>
    <dc:creator>Sanchit_goyal</dc:creator>
    <dc:date>2020-09-24T08:15:00Z</dc:date>
    <item>
      <title>addition and subtraction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/addition-and-subtraction/m-p/686297#M208214</link>
      <description>&lt;P&gt;I have a data set test as shown below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data test;&lt;BR /&gt;input brand $ loan;&lt;BR /&gt;datalines;&lt;BR /&gt;mini&amp;nbsp; &amp;nbsp; 100&lt;BR /&gt;mini&amp;nbsp; &amp;nbsp; &amp;nbsp;20&lt;BR /&gt;mini&amp;nbsp; &amp;nbsp; &amp;nbsp;30&lt;BR /&gt;toyota&amp;nbsp; 120&lt;BR /&gt;toyota&amp;nbsp; 10&lt;BR /&gt;toyota&amp;nbsp; 20&lt;BR /&gt;toyota&amp;nbsp; 12&lt;BR /&gt;toyota&amp;nbsp; 34&lt;BR /&gt;audi&amp;nbsp; &amp;nbsp;320&lt;BR /&gt;audi&amp;nbsp; &amp;nbsp;200&lt;BR /&gt;audi&amp;nbsp; &amp;nbsp;80&lt;BR /&gt;;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want output to be shown as&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;mini&amp;nbsp; &lt;STRONG&gt;70&lt;/STRONG&gt; (100 - 20 - 30 )&lt;BR /&gt;mini 20&lt;BR /&gt;mini 30&lt;BR /&gt;toyota&amp;nbsp; &lt;STRONG&gt;44&lt;/STRONG&gt; (120 - 10 - 20 - 12- 34)&lt;BR /&gt;toyota 10&lt;BR /&gt;toyota 20&lt;BR /&gt;toyota 12&lt;BR /&gt;toyota 34&lt;BR /&gt;audi&amp;nbsp; &lt;STRONG&gt;40&lt;/STRONG&gt;&amp;nbsp; (320 - 200 - 80)&lt;BR /&gt;audi 200&lt;BR /&gt;audi 80&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I only wanted to know how to come at those bold values.&lt;/P&gt;&lt;P&gt;Kindly help.&lt;/P&gt;&lt;P&gt;Thanks! in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 08:15:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/addition-and-subtraction/m-p/686297#M208214</guid>
      <dc:creator>Sanchit_goyal</dc:creator>
      <dc:date>2020-09-24T08:15:00Z</dc:date>
    </item>
    <item>
      <title>Re: addition and subtraction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/addition-and-subtraction/m-p/686303#M208216</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/348936"&gt;@Sanchit_goyal&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[...]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want output to be shown as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;mini&amp;nbsp; &lt;STRONG&gt;70&lt;/STRONG&gt; (100 - 20 - 30 )&lt;BR /&gt;mini 20&lt;BR /&gt;mini 30&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;70? Is this a typo?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 08:50:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/addition-and-subtraction/m-p/686303#M208216</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-09-24T08:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: addition and subtraction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/addition-and-subtraction/m-p/686304#M208217</link>
      <description>&lt;P&gt;Try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   length _loan 8;
   drop _loan;
   
   do _n_ = 1 by 1 until(last.brand);
      set test;
      by brand notsorted;
      
      if first.brand then _loan = loan;
      else _loan = _loan - loan;      
   end;
   
   loan = _loan;
   output;
   
   do _n_ = 1 by 1 until(last.brand);
      set test;
      by brand notsorted;
      
      if not first.brand then output;      
   end;   
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Sep 2020 08:57:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/addition-and-subtraction/m-p/686304#M208217</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-09-24T08:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: addition and subtraction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/addition-and-subtraction/m-p/686305#M208218</link>
      <description>&lt;P&gt;no, 70 is not a typo.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;70 shows that the output should be 100 - 20 - 30. Like if you see in the Brand "mini" , its first.brand loan value is 100 . so for every first.brand loan value , output should be first value minus the rest of the value within that brand group.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;similary for toyota , its first loan value should come out to be 44.&lt;/P&gt;&lt;P&gt;and for audi , its first loan value should come out to be 40.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope you understood!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 08:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/addition-and-subtraction/m-p/686305#M208218</guid>
      <dc:creator>Sanchit_goyal</dc:creator>
      <dc:date>2020-09-24T08:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: addition and subtraction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/addition-and-subtraction/m-p/686314#M208223</link>
      <description>&lt;P&gt;Here is a solution that works with the data you have shown, except that I think the "70" actually&amp;nbsp;&lt;STRONG&gt;is&lt;/STRONG&gt; a typo (100-20-30=&lt;STRONG&gt;50&lt;/STRONG&gt;)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set test nobs=nobs;
  by brand notsorted;
  if first.brand then do _N_=_N_+1 to nobs;
    set test(rename=(brand=_brand loan=_loan)) point=_N_;
    if _brand ne brand then leave;
    loan=loan-_loan;
    end;
  drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I used NOTSORTED because your example data is grouped by BRAND but not in sort order. You may want to use a PROC SORT first instead.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 09:36:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/addition-and-subtraction/m-p/686314#M208223</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-09-24T09:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: addition and subtraction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/addition-and-subtraction/m-p/686316#M208225</link>
      <description>&lt;P&gt;100 - 20 = 80&lt;/P&gt;
&lt;P&gt;80 - 30 = 50&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 09:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/addition-and-subtraction/m-p/686316#M208225</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-09-24T09:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: addition and subtraction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/addition-and-subtraction/m-p/686364#M208254</link>
      <description>&lt;P&gt;As long as we exist in this universe and use a decimal system, the result of 100 - 20 - 30 will be 50.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 13:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/addition-and-subtraction/m-p/686364#M208254</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-24T13:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: addition and subtraction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/addition-and-subtraction/m-p/686372#M208260</link>
      <description>Yeah yeah... that was my bad, I was multitasking so thats puts in&lt;BR /&gt;confusion..&lt;BR /&gt;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 24 Sep 2020 13:38:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/addition-and-subtraction/m-p/686372#M208260</guid>
      <dc:creator>Sanchit_goyal</dc:creator>
      <dc:date>2020-09-24T13:38:07Z</dc:date>
    </item>
  </channel>
</rss>

