<?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: Update values on missing consecutive in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Update-values-on-missing-consecutive/m-p/691774#M24853</link>
    <description>&lt;P&gt;one other option would be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T;
input ID L EXP;
Datalines;
1 1 10
1 2 20
1 4 20
1 5 20
2 1 10
2 2 60
3 2 50
3 3 50
;
run;

data want;
  set T;
  by id;
  dif_L = dif(L);

  if first.ID then 
    do; 
      _tmp_EXP = .;
      if 1 ne L then _tmp_EXP + 0; 
    end;
  else if dif_L ne 1 then 
         do; 
           _tmp_EXP + 0; 
         end;
  
  if _tmp_EXP = 0 then EXP = 0;

  drop _tmp_EXP dif_L;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Thu, 15 Oct 2020 08:55:26 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2020-10-15T08:55:26Z</dc:date>
    <item>
      <title>Update values on missing consecutive</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-values-on-missing-consecutive/m-p/691762#M24850</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T;
input ID L EXP;
Datalines;
1 1 10
1 2 20
1 4 20&lt;BR /&gt;1 5 20
2 1 10
2 2 60
3 2 50
3 3 50
;
data want;
 do until(last.id);
  set T;
  by id;
  if l&amp;lt;=1 then flag=1;
 end;

 do until(last.id);
  set T;
  by id;
  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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;with this code, this is the correct output (per ID if First.ID and L&amp;gt;1 all the sequential Exp updated to 0)&lt;/P&gt;
&lt;P&gt;1 1 10&lt;BR /&gt;1 2 20&lt;BR /&gt;1 4 20&lt;/P&gt;
&lt;P&gt;1 5 20&lt;BR /&gt;2 1 10&lt;BR /&gt;2 2 60&lt;BR /&gt;3 2 0&lt;BR /&gt;3 3 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can this code be amended in order if per ID the sequence of L is broken, the rest Exp to update to 0? So the output should be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 1 10&lt;BR /&gt;1 2 20&lt;BR /&gt;1 4 0&lt;/P&gt;
&lt;P&gt;1 5 0&lt;BR /&gt;2 1 10&lt;BR /&gt;2 2 60&lt;BR /&gt;3 2 0&lt;BR /&gt;3 3 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2020 07:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-values-on-missing-consecutive/m-p/691762#M24850</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-10-15T07:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: Update values on missing consecutive</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-values-on-missing-consecutive/m-p/691770#M24851</link>
      <description>&lt;P&gt;Manipulate flag in the second DO loop if the condition is met:&lt;/P&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;</description>
      <pubDate>Thu, 15 Oct 2020 08:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-values-on-missing-consecutive/m-p/691770#M24851</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-15T08:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: Update values on missing consecutive</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-values-on-missing-consecutive/m-p/691773#M24852</link>
      <description>&lt;P&gt;It works. Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2020 08:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-values-on-missing-consecutive/m-p/691773#M24852</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-10-15T08:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: Update values on missing consecutive</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-values-on-missing-consecutive/m-p/691774#M24853</link>
      <description>&lt;P&gt;one other option would be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T;
input ID L EXP;
Datalines;
1 1 10
1 2 20
1 4 20
1 5 20
2 1 10
2 2 60
3 2 50
3 3 50
;
run;

data want;
  set T;
  by id;
  dif_L = dif(L);

  if first.ID then 
    do; 
      _tmp_EXP = .;
      if 1 ne L then _tmp_EXP + 0; 
    end;
  else if dif_L ne 1 then 
         do; 
           _tmp_EXP + 0; 
         end;
  
  if _tmp_EXP = 0 then EXP = 0;

  drop _tmp_EXP dif_L;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2020 08:55:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-values-on-missing-consecutive/m-p/691774#M24853</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-10-15T08:55:26Z</dc:date>
    </item>
    <item>
      <title>Re: Update values on missing consecutive</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-values-on-missing-consecutive/m-p/691775#M24854</link>
      <description>&lt;P&gt;This works too. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2020 09:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-values-on-missing-consecutive/m-p/691775#M24854</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-10-15T09:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Update values on missing consecutive</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-values-on-missing-consecutive/m-p/691786#M24855</link>
      <description>&lt;PRE&gt;data T;
input ID L EXP;
Datalines;
1 1 10
1 2 20
1 4 20
1 5 20
2 1 10
2 2 60
3 2 50
3 3 50
;
data tt;
 set t;
 by id;
 if first.id or dif(l) ne 1 then group+1;
run;
data want;
 do until(last.group);
  set Tt;
  by group;
  if first.group and l&amp;lt;=1 then flag=1;
 end;

 do until(last.group);
  set Tt;
  by group;
  if not flag then exp=0;
  output;
 end;
 drop flag group;
 run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Oct 2020 10:32:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-values-on-missing-consecutive/m-p/691786#M24855</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-10-15T10:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Update values on missing consecutive</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-values-on-missing-consecutive/m-p/691796#M24856</link>
      <description>It works. Thanks.</description>
      <pubDate>Thu, 15 Oct 2020 11:49:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-values-on-missing-consecutive/m-p/691796#M24856</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-10-15T11:49:04Z</dc:date>
    </item>
  </channel>
</rss>

