<?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: Recursively fill missing values in rows in a panel dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Recursively-fill-missing-values-in-rows-in-a-panel-dataset/m-p/832873#M329241</link>
    <description>&lt;P&gt;You can't RETAIN a variable that exists in the input data set.&amp;nbsp;It will always be overwritten by the incoming value when the SET statement executes. Try this instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	retain oldvar;
	drop oldvar;
	set have;
	by id1 id2;
	if first.id1 and first.id2 then oldvar=var;
	else if missing(var) then var=oldvar*2;&lt;BR /&gt;    /* Set OLDVAR up for the next row if the value was calculated */
	oldvar=var;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 12 Sep 2022 12:13:52 GMT</pubDate>
    <dc:creator>SASJedi</dc:creator>
    <dc:date>2022-09-12T12:13:52Z</dc:date>
    <item>
      <title>Recursively fill missing values in rows in a panel dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recursively-fill-missing-values-in-rows-in-a-panel-dataset/m-p/832868#M329239</link>
      <description>&lt;P&gt;As a follow-up to&amp;nbsp;&lt;LI-MESSAGE title="Recursively filling rows" uid="832534" url="https://communities.sas.com/t5/SAS-Programming/Recursively-filling-rows/m-p/832534#U832534" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;I have another question. I want to achieve the same (recursively replace missing values), but using panel data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the example below I want to replace missing values in a dataset in a way that value of var for each row with missing value equals to the value of var for previous year &lt;STRONG&gt;for the same id1 and id2&lt;/STRONG&gt; multiplied by two:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	do year = 2010 to 2015;
		do id1 = 1 to 3;
			do id2 = 1 to 5;
				year = year;
				id1 = id1;
				id2 = id2;
				output;
			end;
		end;
	end;
run;

data have;
	call streaminit(123);
	set have;
	if year = 2010 then var = rand('Normal', 10, 1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So, in row 16 (year = 2011, id1 = 1, id2 = 1) I want 10.083937704 * 2 = 20.16788, then in row 31&amp;nbsp;(year = 2012, id1 = 1, id2 = 1) I want 20.16788 * 2 = 40.33575.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried to combine retain and "by" but it's not working:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = have;
	by id1 id2 year;
run;

data want;
	set have;
	by id1 id2;
	retain var;
	if first.id1 and first.id2 then var = var;
	else var = var*2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Many thanks in advance for any suggestions&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 11:43:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recursively-fill-missing-values-in-rows-in-a-panel-dataset/m-p/832868#M329239</guid>
      <dc:creator>chris2377</dc:creator>
      <dc:date>2022-09-12T11:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: Recursively fill missing values in rows in a panel dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recursively-fill-missing-values-in-rows-in-a-panel-dataset/m-p/832873#M329241</link>
      <description>&lt;P&gt;You can't RETAIN a variable that exists in the input data set.&amp;nbsp;It will always be overwritten by the incoming value when the SET statement executes. Try this instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	retain oldvar;
	drop oldvar;
	set have;
	by id1 id2;
	if first.id1 and first.id2 then oldvar=var;
	else if missing(var) then var=oldvar*2;&lt;BR /&gt;    /* Set OLDVAR up for the next row if the value was calculated */
	oldvar=var;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Sep 2022 12:13:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recursively-fill-missing-values-in-rows-in-a-panel-dataset/m-p/832873#M329241</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2022-09-12T12:13:52Z</dc:date>
    </item>
  </channel>
</rss>

