<?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 last and first observation by subject in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/calculate-difference-between-last-and-first-observation-by/m-p/850903#M336272</link>
    <description>&lt;P&gt;Can be done in one step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by cust_id;
retain wealth_first;
if first.cust_id then wealth_first = wealth;
if last.cust_id;
wealth_last = wealth;
dif = wealth_last - wealth_first;
drop wealth;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 23 Dec 2022 06:13:08 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-12-23T06:13:08Z</dc:date>
    <item>
      <title>calculate difference between last and first observation by subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-difference-between-last-and-first-observation-by/m-p/850901#M336270</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to calculate for each customer the difference between wealth in first time and last time.&lt;/P&gt;
&lt;P&gt;I want to create 2 wanted data set.&lt;/P&gt;
&lt;P&gt;In "want1"&amp;nbsp; data set the difference between last and first will be dispalyed in last row.&lt;/P&gt;
&lt;P&gt;In "Want2" data set only dispaly the last row with the information of wealth_first,wealth_last,difference&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what is the way to do it please?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
Input Cust_ID  time  $ wealth;
cards;
1 2022-01 100
1 2022-02 90
1 2022-03 85
1 2022-04 130
2 2022-01 400
2 2022-02 410
2 2022-03 380
2 2022-04 270
2 2022-05 150
2 2022-06 40
;
Run;

Data want1;
Input Cust_ID  time  $ wealth dif;
1 2022-01 100 .
1 2022-02 90 .
1 2022-03 85 .
1 2022-04 130 30
2 2022-01 400 .
2 2022-02 410 .
2 2022-03 380 .
2 2022-04 270 .
2 2022-05 150  
2 2022-06 40 -360
;
Run;


Data want1;
Input Cust_ID  time  $   wealth_first  wealth_last dif;
1 2022-04 100 130 30
2 2022-06 400 40 -360
;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Dec 2022 05:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-difference-between-last-and-first-observation-by/m-p/850901#M336270</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-12-23T05:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference between last and first observation by subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-difference-between-last-and-first-observation-by/m-p/850903#M336272</link>
      <description>&lt;P&gt;Can be done in one step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by cust_id;
retain wealth_first;
if first.cust_id then wealth_first = wealth;
if last.cust_id;
wealth_last = wealth;
dif = wealth_last - wealth_first;
drop wealth;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Dec 2022 06:13:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-difference-between-last-and-first-observation-by/m-p/850903#M336272</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-12-23T06:13:08Z</dc:date>
    </item>
  </channel>
</rss>

