<?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: Assign 999 to subsequent blank rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assign-999-to-subsequent-blank-rows/m-p/748658#M235138</link>
    <description>&lt;P&gt;How about this one .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd dlm=" " truncover;
input ID $ Sequence section $ value;
datalines;
1 1 a 0
1 2 b  
1 3 c 1
1 4 d 0
1 5 e 0
2 1 a 1
2 2 b 1
2 3 c  
2 4 d 2
2 5 e 2
2 6 f  
2 7 g  
2 8 h 0
3 1 a .
3 2 b 1
4 1 a 0
4 2 b
;
run;
data want;
 do until(last.value);
  set have;
  by id value notsorted;
  if first.id then first=1;
  if last.id then last=1;
 end;

  do until(last.value);
  set have;
  by id value notsorted;
  desired=value;
  if not first and not last and missing(value) then desired=999;
  output;
 end;
 drop first last;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 17 Jun 2021 12:20:57 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2021-06-17T12:20:57Z</dc:date>
    <item>
      <title>Assign 999 to subsequent blank rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-999-to-subsequent-blank-rows/m-p/748643#M235128</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The below code doesnt consider subsequent blank values if there are two or more blank rows in between.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This only works on first blank row. Sorry if wasnt that clear yesterday. Can you please check this for me.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd dlm=" " truncover;
input ID $ Sequence section $ value;
datalines;
1 1 a 0
1 2 b  
1 3 c 1
1 4 d 0
1 5 e 0
2 1 a 1
2 2 b 1
2 3 c  
2 4 d 2
2 5 e 2
2 6 f  
2 7 g  
2 8 h 0
3 1 a .
3 2 b 1
4 1 a 0
4 2 b
;
run;



data want;
set have;
by id;
set /* create a "look-ahead" */
  have (
    firstobs=2
    keep=id value
    rename=(id=_id value=_value)
  )
  have ( /* this is needed to prevent a premature end of the data step */
    obs=1
    keep=id value
    rename=(id=_id value=_value)
  )
;
_lvalue = lag(value);
if
  not (first.id or last.id) and
  value = . and _lvalue ne . and _value ne .
then desired = 999;
else desired = value;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Jun 2021 10:15:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-999-to-subsequent-blank-rows/m-p/748643#M235128</guid>
      <dc:creator>bharath86</dc:creator>
      <dc:date>2021-06-17T10:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Assign 999 to subsequent blank rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-999-to-subsequent-blank-rows/m-p/748644#M235129</link>
      <description>&lt;P&gt;I changed my earlier code to SQL, as multiple comparisons over an arbitrary number of observations can be done there:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd dlm=" " truncover;
input ID $ Sequence section $ value;
datalines;
1 1 a 0
1 2 b  
1 3 c 1
1 4 d 0
1 5 e 0
2 1 a 1
2 2 b 1
2 3 c  
2 4 d 2
2 5 e 2
2 6 f  
2 7 g  
2 8 h 0
3 1 a .
3 2 b 1
4 1 a 0
4 2 b
;

proc sql;
create table want as
  select
    t1.*,
    max(case
      when t1.value ne .
      then t1.value
      else case
        when t2.value ne . and t3.value ne .
        then 999
        else .
      end
    end) as desired
  from have t1 left join have t2
  on t1.id = t2.id and t1.sequence &amp;gt; t2.sequence
  left join have t3
  on t1.id = t3.id and t1.sequence &amp;lt; t3.sequence
  group by t1.id, t1.sequence, t1.section, t1.value
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Jun 2021 10:40:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-999-to-subsequent-blank-rows/m-p/748644#M235129</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-17T10:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Assign 999 to subsequent blank rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-999-to-subsequent-blank-rows/m-p/748658#M235138</link>
      <description>&lt;P&gt;How about this one .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd dlm=" " truncover;
input ID $ Sequence section $ value;
datalines;
1 1 a 0
1 2 b  
1 3 c 1
1 4 d 0
1 5 e 0
2 1 a 1
2 2 b 1
2 3 c  
2 4 d 2
2 5 e 2
2 6 f  
2 7 g  
2 8 h 0
3 1 a .
3 2 b 1
4 1 a 0
4 2 b
;
run;
data want;
 do until(last.value);
  set have;
  by id value notsorted;
  if first.id then first=1;
  if last.id then last=1;
 end;

  do until(last.value);
  set have;
  by id value notsorted;
  desired=value;
  if not first and not last and missing(value) then desired=999;
  output;
 end;
 drop first last;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Jun 2021 12:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-999-to-subsequent-blank-rows/m-p/748658#M235138</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-06-17T12:20:57Z</dc:date>
    </item>
  </channel>
</rss>

