<?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: Calculate difference between first and last observation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-first-and-last-observation/m-p/348532#M80724</link>
    <description>&lt;P&gt;Here is one way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  set have end=last;
  retain first;
  if _n_ eq 1 then first=profit;
  if last then do;
    result=profit-first;
    output;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 09 Apr 2017 17:11:14 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-04-09T17:11:14Z</dc:date>
    <item>
      <title>Calculate difference between first and last observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-first-and-last-observation/m-p/348531#M80723</link>
      <description>&lt;P&gt;I have the following dataset&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input profit;&lt;BR /&gt;datalines;&lt;BR /&gt;52&lt;BR /&gt;34&lt;/P&gt;&lt;P&gt;60&lt;/P&gt;&lt;P&gt;57&lt;/P&gt;&lt;P&gt;70&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I want to write a program that will&amp;nbsp;create a new dataset, &lt;U&gt;&lt;EM&gt;only&lt;/EM&gt; &lt;/U&gt;containing the difference between the first and last&amp;nbsp;observation?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In this case the code would show 70 (last observation) - 52 (first observation), so the output would be 18.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Apr 2017 17:05:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-first-and-last-observation/m-p/348531#M80723</guid>
      <dc:creator>mhinchy</dc:creator>
      <dc:date>2017-04-09T17:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between first and last observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-first-and-last-observation/m-p/348532#M80724</link>
      <description>&lt;P&gt;Here is one way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  set have end=last;
  retain first;
  if _n_ eq 1 then first=profit;
  if last then do;
    result=profit-first;
    output;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Apr 2017 17:11:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-first-and-last-observation/m-p/348532#M80724</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-04-09T17:11:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between first and last observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-first-and-last-observation/m-p/348588#M80732</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data want(drop=_profit);&lt;BR /&gt;set have(firstobs=min);&lt;BR /&gt;set have(rename=(profit=_profit)) nobs=_nobs_ point=_nobs_;&lt;BR /&gt;d=_profit-profit;&lt;BR /&gt;output;&lt;BR /&gt;stop;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naveen Srinivasan&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 04:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-first-and-last-observation/m-p/348588#M80732</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-04-10T04:50:17Z</dc:date>
    </item>
  </channel>
</rss>

