<?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: Double DOW loop to populate missing AVAL records from Last on visit in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Double-DOW-loop-to-populate-missing-AVAL-records-from-Last-on/m-p/840091#M332172</link>
    <description>&lt;P&gt;Actually figured it out myself. Here is the code for anyone interested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do _n_ = 1 by 1 until(last.usubjid);
  set have;
  by usubjid;
  if visit ='Early Termination' and not(missing(aval)) then last_non_missing = aval;
end;
do _n_ = 1 to _n_;
  set have;  
  aval =coalesce(aval,last_non_missing);
  output;
end;
drop last_non_missing;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 22 Oct 2022 15:01:35 GMT</pubDate>
    <dc:creator>smackerz1988</dc:creator>
    <dc:date>2022-10-22T15:01:35Z</dc:date>
    <item>
      <title>Double DOW loop to populate missing AVAL records from Last on visit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-DOW-loop-to-populate-missing-AVAL-records-from-Last-on/m-p/840083#M332168</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I'm creating a parameter for a dataset and for each result (AVAL) there is a particular strategy (Composite Strategy 2). For this one I need to impute the AVAL from the last visit (DTYPE=LOV) (In this case Early termination and if an AVAL is present in that visit I need to use that AVAL for previous visits where AVAL is missing. My question is how do I do a double DOW loop to achieve this and&lt;SPAN&gt;&amp;nbsp;get the missing AVAL records to populate with the AVAL from the Early Termination visit but without overwriting any visits where AVAL is present (In this example data the Week 2 AVAL). Here is a snippet of my current dataset&lt;/SPAN&gt;&amp;nbsp;and my desired output&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;
input  PARAMCD $ STRATEGY :$30. DTYPE $ SUBJID $ VISIT :$30. AVAL :8.; 
infile datalines dlm = '|';
datalines;
TOTEDPS1|Composite strategy 2|LOV|1001|Week 2|61.2
TOTEDPS1|Composite strategy 2|LOV|1001|Week 4|
TOTEDPS1|Composite strategy 2|LOV|1001|Week 8|
TOTEDPS1|Composite strategy 2|LOV|1001|Week 12|
TOTEDPS1|Composite strategy 2|LOV|1001|Week 16|
TOTEDPS1|Composite strategy 2|LOV|1001|Early Termination|43.5
TOTEDPS1|Composite strategy 2|LOV|1002|Week 2|16
TOTEDPS1|Composite strategy 2|LOV|1002|Week 4|
TOTEDPS1|Composite strategy 2|LOV|1002|Week 8|
TOTEDPS1|Composite strategy 2|LOV|1002|Week 12|
TOTEDPS1|Composite strategy 2|LOV|1002|Week 16|
TOTEDPS1|Composite strategy 2|LOV|1002|Early Termination|6.6
;
run;

data want;
input  PARAMCD $ STRATEGY :$30. DTYPE $ SUBJID $ VISIT :$30. AVAL :8.; 
infile datalines dlm = '|';
datalines;
TOTEDPS1|Composite strategy 2|LOV|1001|Week 2|61.2
TOTEDPS1|Composite strategy 2|LOV|1001|Week 4|43.5
TOTEDPS1|Composite strategy 2|LOV|1001|Week 8|43.5
TOTEDPS1|Composite strategy 2|LOV|1001|Week 12|43.5
TOTEDPS1|Composite strategy 2|LOV|1001|Week 16|43.5
TOTEDPS1|Composite strategy 2|LOV|1001|Early Termination|43.5
TOTEDPS1|Composite strategy 2|LOV|1002|Week 2|16
TOTEDPS1|Composite strategy 2|LOV|1002|Week 4|6.6
TOTEDPS1|Composite strategy 2|LOV|1002|Week 8|6.6
TOTEDPS1|Composite strategy 2|LOV|1002|Week 12|6.6
TOTEDPS1|Composite strategy 2|LOV|1002|Week 16|6.6
TOTEDPS1|Composite strategy 2|LOV|1002|Early Termination|6.6
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2022 14:43:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-DOW-loop-to-populate-missing-AVAL-records-from-Last-on/m-p/840083#M332168</guid>
      <dc:creator>smackerz1988</dc:creator>
      <dc:date>2022-10-22T14:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: Double DOW loop to populate missing AVAL records from Last on visit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-DOW-loop-to-populate-missing-AVAL-records-from-Last-on/m-p/840091#M332172</link>
      <description>&lt;P&gt;Actually figured it out myself. Here is the code for anyone interested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do _n_ = 1 by 1 until(last.usubjid);
  set have;
  by usubjid;
  if visit ='Early Termination' and not(missing(aval)) then last_non_missing = aval;
end;
do _n_ = 1 to _n_;
  set have;  
  aval =coalesce(aval,last_non_missing);
  output;
end;
drop last_non_missing;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Oct 2022 15:01:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-DOW-loop-to-populate-missing-AVAL-records-from-Last-on/m-p/840091#M332172</guid>
      <dc:creator>smackerz1988</dc:creator>
      <dc:date>2022-10-22T15:01:35Z</dc:date>
    </item>
  </channel>
</rss>

