<?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: How to calculate the difference between two observation on different rows in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-the-difference-between-two-observation-on/m-p/401256#M66756</link>
    <description>&lt;PRE&gt;data want;
  merge 
    have 
    have(keep=var2 rename=(var2=next_var2) firstobs=2) 
      end=done;
  if not done then
    tot=var1-next_var2;
  drop next_var2;
run;
  &lt;/PRE&gt;</description>
    <pubDate>Thu, 05 Oct 2017 09:39:07 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2017-10-05T09:39:07Z</dc:date>
    <item>
      <title>How to calculate the difference between two observation on different rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-the-difference-between-two-observation-on/m-p/401245#M66754</link>
      <description>&lt;DIV class="lia-message-heading lia-component-message-header"&gt;&amp;nbsp;Hi,&lt;/DIV&gt;&lt;DIV class="lia-message-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table that shows an ID and two numeric variables, as in the example below:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;VAR1&lt;/TD&gt;&lt;TD&gt;VAR2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ID1&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ID2&lt;/TD&gt;&lt;TD&gt;21&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ID3&lt;/TD&gt;&lt;TD&gt;22&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to add in this table an other column (e.g. TOT) that calculate the difference between var1 to the first&amp;nbsp;row and var2 to the second and so on, as in the example below:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;VAR1&lt;/TD&gt;&lt;TD&gt;VAR2&lt;/TD&gt;&lt;TD&gt;TOT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ID1&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ID2&lt;/TD&gt;&lt;TD&gt;21&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ID3&lt;/TD&gt;&lt;TD&gt;22&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;22&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could anyone help me?&lt;/P&gt;&lt;P&gt;Thanks for your assistance.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 05 Oct 2017 09:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-the-difference-between-two-observation-on/m-p/401245#M66754</guid>
      <dc:creator>Trus</dc:creator>
      <dc:date>2017-10-05T09:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two observation on different rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-the-difference-between-two-observation-on/m-p/401256#M66756</link>
      <description>&lt;PRE&gt;data want;
  merge 
    have 
    have(keep=var2 rename=(var2=next_var2) firstobs=2) 
      end=done;
  if not done then
    tot=var1-next_var2;
  drop next_var2;
run;
  &lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Oct 2017 09:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-the-difference-between-two-observation-on/m-p/401256#M66756</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-10-05T09:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two observation on different rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-the-difference-between-two-observation-on/m-p/401262#M66757</link>
      <description>Thank you so much!</description>
      <pubDate>Thu, 05 Oct 2017 10:09:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-the-difference-between-two-observation-on/m-p/401262#M66757</guid>
      <dc:creator>Trus</dc:creator>
      <dc:date>2017-10-05T10:09:12Z</dc:date>
    </item>
  </channel>
</rss>

