<?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 Subtracting from previous row value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subtracting-from-previous-row-value/m-p/600144#M173394</link>
    <description>&lt;P&gt;Hi, I am trying to create a waterfall in which I need subtract a value of a var1 in previous row from value of var2 of the current row.&lt;/P&gt;&lt;P&gt;For example&lt;/P&gt;&lt;P&gt;Id var1 var2 result&lt;BR /&gt;1 50 50 .&lt;BR /&gt;2 45 5 50-5= 45&lt;BR /&gt;3 30 15 45-15=30&lt;BR /&gt;4 20 10 30-10=20&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Is it possible to do so in proc report... If so then how?&lt;BR /&gt;Thanks in advance.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Oct 2019 18:48:50 GMT</pubDate>
    <dc:creator>Mei121</dc:creator>
    <dc:date>2019-10-29T18:48:50Z</dc:date>
    <item>
      <title>Subtracting from previous row value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtracting-from-previous-row-value/m-p/600144#M173394</link>
      <description>&lt;P&gt;Hi, I am trying to create a waterfall in which I need subtract a value of a var1 in previous row from value of var2 of the current row.&lt;/P&gt;&lt;P&gt;For example&lt;/P&gt;&lt;P&gt;Id var1 var2 result&lt;BR /&gt;1 50 50 .&lt;BR /&gt;2 45 5 50-5= 45&lt;BR /&gt;3 30 15 45-15=30&lt;BR /&gt;4 20 10 30-10=20&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Is it possible to do so in proc report... If so then how?&lt;BR /&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2019 18:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtracting-from-previous-row-value/m-p/600144#M173394</guid>
      <dc:creator>Mei121</dc:creator>
      <dc:date>2019-10-29T18:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting from previous row value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtracting-from-previous-row-value/m-p/600145#M173395</link>
      <description>&lt;P&gt;Easy in a DATA step using the LAG() function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure it can be done in PROC REPORT, but you can always do the math in the DATA step and then use PROC REPORT on the results.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2019 18:50:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtracting-from-previous-row-value/m-p/600145#M173395</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-29T18:50:40Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting from previous row value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtracting-from-previous-row-value/m-p/600265#M173455</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297355"&gt;@Mei121&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Create a view:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                         
  input Id var1 var2 ;              
  cards ;                           
1 50 50                             
2 45  5                             
3 30 15                             
4 20 10                             
;                                   
run ;                               
                                    
data v / view = v ;                 
  set have ;                        
  _n_ = lag (var1) ;                
  if nmiss (_n_) then result = _n_ ;
  else result = _n_ - var2 ;        
run ;                               
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then run your proc REPORT against the view V as input.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 05:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtracting-from-previous-row-value/m-p/600265#M173455</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-30T05:58:03Z</dc:date>
    </item>
  </channel>
</rss>

