<?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: Spot the non-consecutive values and update accordingly a different column data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Spot-the-non-consecutive-values-and-update-accordingly-a/m-p/693701#M287446</link>
    <description>It works for this samples dataset with taking out the (or Lorax=4) condition.&lt;BR /&gt;I'm testing it in other samples as well, see how it responds.&lt;BR /&gt;Thanks.</description>
    <pubDate>Fri, 23 Oct 2020 11:34:03 GMT</pubDate>
    <dc:creator>cmemtsa</dc:creator>
    <dc:date>2020-10-23T11:34:03Z</dc:date>
    <item>
      <title>Spot the non-consecutive values and update accordingly a different column data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Spot-the-non-consecutive-values-and-update-accordingly-a/m-p/693667#M287442</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T;
input ID L EXP;
Datalines;
A1 1 10
A1 1 10
A1 2 20&lt;BR /&gt;A1 2 20
A1 4 20
A1 4 20
A1 5 20
A2 1 10
A2 2 60
A2 2 60
A2 3 60
A2 3 60
A2 5 50&lt;BR /&gt;A2 7 50
A3 2 60
A3 4 60
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data want;
do until (last.id);
  set T;
  by id;

  if l &amp;lt;= 1 then flag = 1;
end;

put flag=;

do until(last.id);
  set T;
  by id;
  if not first.id and lag(l) ne l - 1  then flag = 0;
  if not flag then exp = 0;
  output;
end;
drop flag;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;On this dataset (already sorted by ID, L) , I want to update EXP to 0 in these cases:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1. The First.L per ID is not 1 (and all the subsequent to it)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2. The first time the sequence of L is broken per ID and all the subsequent to it. (there are repetitions of L)&lt;/P&gt;
&lt;P&gt;i.e the output should be&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A1 1 10&lt;BR /&gt;A1 1 10&lt;BR /&gt;A1 2 20&lt;/P&gt;
&lt;P&gt;A1 2 20&lt;/P&gt;
&lt;P&gt;A1 4 0&lt;BR /&gt;A1 4 0&lt;BR /&gt;A1 5 0&lt;BR /&gt;A2 1 10&lt;BR /&gt;A2 2 60&lt;BR /&gt;A2 2 60&lt;BR /&gt;A2 3 60&lt;BR /&gt;A2 3 60&lt;BR /&gt;A2 5 0&lt;/P&gt;
&lt;P&gt;A2 7 0&lt;BR /&gt;A3 2 0&lt;BR /&gt;A3 4 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above code does not properly work in this case.&lt;/P&gt;
&lt;P&gt;How should be amended?&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2020 07:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Spot-the-non-consecutive-values-and-update-accordingly-a/m-p/693667#M287442</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-10-23T07:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: Spot the non-consecutive values and update accordingly a different column data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Spot-the-non-consecutive-values-and-update-accordingly-a/m-p/693675#M287443</link>
      <description>&lt;P&gt;Please explain what "The first time the sequence of L is broken per ID"&amp;nbsp; means.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2020 08:38:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Spot-the-non-consecutive-values-and-update-accordingly-a/m-p/693675#M287443</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-10-23T08:38:28Z</dc:date>
    </item>
    <item>
      <title>Re: Spot the non-consecutive values and update accordingly a different column data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Spot-the-non-consecutive-values-and-update-accordingly-a/m-p/693676#M287444</link>
      <description>e.g. in A1 we have L with sequence  1,1,2, 2, (which is normal: could be also 1,2,2)  and then goes to 4. All EXP should be set to 0 for L=4 and all the subsequent (per ID).</description>
      <pubDate>Fri, 23 Oct 2020 08:45:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Spot-the-non-consecutive-values-and-update-accordingly-a/m-p/693676#M287444</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-10-23T08:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: Spot the non-consecutive values and update accordingly a different column data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Spot-the-non-consecutive-values-and-update-accordingly-a/m-p/693685#M287445</link>
      <description>&lt;P&gt;Maybe this solves it, i renamed "L" to increase readability.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   by ID;

   retain reset;

   LastLorax = lag(Lorax);

   if first.Id then do;
      LastLorax = .;
      reset = 0;

      if Lorax ^= 1 then do;         
         reset = 1;
      end;
   end;
   else do;
      if Lorax - LastLorax &amp;gt; 1 or Lorax = 4 then do;
         reset = 1;
      end;
   end;

   if reset then do;
      exp = 0;
   end;

   keep ID Lorax Exp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Oct 2020 09:41:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Spot-the-non-consecutive-values-and-update-accordingly-a/m-p/693685#M287445</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-10-23T09:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: Spot the non-consecutive values and update accordingly a different column data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Spot-the-non-consecutive-values-and-update-accordingly-a/m-p/693701#M287446</link>
      <description>It works for this samples dataset with taking out the (or Lorax=4) condition.&lt;BR /&gt;I'm testing it in other samples as well, see how it responds.&lt;BR /&gt;Thanks.</description>
      <pubDate>Fri, 23 Oct 2020 11:34:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Spot-the-non-consecutive-values-and-update-accordingly-a/m-p/693701#M287446</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-10-23T11:34:03Z</dc:date>
    </item>
  </channel>
</rss>

