<?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: I want to subtract in one column values with previous value by groups in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-subtract-in-one-column-values-with-previous-value-by/m-p/306825#M65655</link>
    <description>&lt;P&gt;While you now have a suggestion that works for the sample data you posted, I'm curious about one possibility.&amp;nbsp; Is it possible that you have a V2 record followed by a V3 record, but they belong to different IDs?&amp;nbsp; (If that's possible, I feel confident that the proposed suggestion could be modified to handle that case.)&lt;/P&gt;</description>
    <pubDate>Mon, 24 Oct 2016 14:44:18 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-10-24T14:44:18Z</dc:date>
    <item>
      <title>I want to subtract in one column values with previous value by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-subtract-in-one-column-values-with-previous-value-by/m-p/306784#M65635</link>
      <description>&lt;P&gt;data event;&lt;BR /&gt;input ID event $ value;&lt;BR /&gt;cards;&lt;BR /&gt;1002 V1 1999&lt;BR /&gt;1002 V2 1985&lt;BR /&gt;1002 V3 1986&lt;BR /&gt;1003 V1 1999&lt;BR /&gt;1003 V2 1984&lt;BR /&gt;1003 V3 1983&lt;BR /&gt;1004 V1 2000&lt;BR /&gt;1004 V2 1999&lt;BR /&gt;1004 V3 1999&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;I want to substract only where ever the v2 and v3 values. for example:&lt;BR /&gt;if event = v3 and lag of event =v2 then val= v3-v2;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2016 13:59:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-subtract-in-one-column-values-with-previous-value-by/m-p/306784#M65635</guid>
      <dc:creator>SrikanthY</dc:creator>
      <dc:date>2016-10-24T13:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: I want to subtract in one column values with previous value by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-subtract-in-one-column-values-with-previous-value-by/m-p/306802#M65648</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA event;
   length lag1_event $2 lag1_value 8;
   set event;
   lag1_event=lag1(event);
   lag1_value=lag1(value);
   if event eq 'V3' and lag1_event eq 'V2' then val=value-lag1_value;&lt;BR /&gt;drop lag1:;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Cheers,&lt;BR /&gt;Oligolas&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2016 14:16:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-subtract-in-one-column-values-with-previous-value-by/m-p/306802#M65648</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2016-10-24T14:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: I want to subtract in one column values with previous value by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-subtract-in-one-column-values-with-previous-value-by/m-p/306825#M65655</link>
      <description>&lt;P&gt;While you now have a suggestion that works for the sample data you posted, I'm curious about one possibility.&amp;nbsp; Is it possible that you have a V2 record followed by a V3 record, but they belong to different IDs?&amp;nbsp; (If that's possible, I feel confident that the proposed suggestion could be modified to handle that case.)&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2016 14:44:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-subtract-in-one-column-values-with-previous-value-by/m-p/306825#M65655</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-10-24T14:44:18Z</dc:date>
    </item>
    <item>
      <title>Re: I want to subtract in one column values with previous value by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-want-to-subtract-in-one-column-values-with-previous-value-by/m-p/306847#M65661</link>
      <description>&lt;P&gt;Good point.&lt;/P&gt;&lt;P&gt;If the IDs are relevant you need to check them as well.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA event;
   length lag1_event $2 lag1_value lag1_id 8;
   set event;
   lag1_event=lag1(event);
   lag1_value=lag1(value);
   lag1_id=lag1(id);
   if id eq lag1_id 
   and event eq 'V3' 
   and lag1_event eq 'V2' then val=value-lag1_value;
   drop lag1:;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Oct 2016 15:17:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-want-to-subtract-in-one-column-values-with-previous-value-by/m-p/306847#M65661</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2016-10-24T15:17:43Z</dc:date>
    </item>
  </channel>
</rss>

