<?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: fill in missing values with the previous values for panel in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/fill-in-missing-values-with-the-previous-values-for-panel/m-p/908248#M358458</link>
    <description>&lt;P&gt;You can use the UPDATE statement to implement last observation carried forward.&amp;nbsp; To prevent it from applying to the other variables just re-read the observation without the ones you do want carried forward.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  update have(obs=0) have;
  by gvkey;
  set have(drop=shrcd);
  output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to move values backwards in time then you will need a different method.&lt;/P&gt;</description>
    <pubDate>Fri, 15 Dec 2023 16:35:38 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-12-15T16:35:38Z</dc:date>
    <item>
      <title>fill in missing values with the previous values for panel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fill-in-missing-values-with-the-previous-values-for-panel/m-p/908227#M358456</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;  
   input gvkey $ year shrcd;  
   datalines;  
2477 2001 11
2477 2002 11
2477 2003 
3156 2001 10
3156 2002 10
3156 2003 
3156 2004 
3010 2001 
3010 2002 
3010 2003 
3010 2004 
;  
proc print data=have;  
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;I am new to SAS, so the data step to input the data that I am writing here may contain some flaws, but I did my best to help you visualize my panel.&amp;nbsp; I only want to fill in the column "shrcd" (as there actually many columns in my dataset with missing values) if this gvkey once had its shrcd filled in.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hence, gvkey 2477 should have its 2003's shrcd as 11, and gvkey 3156 should have both its 2003 and 2004 filled in as 10, but gvkey 3010 should NOT have anything filled in for its shrcd.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could I kindly seek assistance on how to do my request? Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2023 15:56:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fill-in-missing-values-with-the-previous-values-for-panel/m-p/908227#M358456</guid>
      <dc:creator>Jarvin99</dc:creator>
      <dc:date>2023-12-15T15:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: fill in missing values with the previous values for panel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fill-in-missing-values-with-the-previous-values-for-panel/m-p/908240#M358457</link>
      <description>&lt;P&gt;If you are working with Time Series Data and Panel data, you will have SAS/ETS and SAS Econometrics available.&lt;BR /&gt;So you can use PROC EXPAND for this task.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;  
   input gvkey $ year shrcd;
   yeardt=MDY(12,31,year);
   format yeardt date9.; 
   datalines;  
2477 2001 11
2477 2002 11
2477 2003 . 
3156 2001 10
3156 2002 10
3156 2003 .
3156 2004 .
3010 2001 .
3010 2002 .
3010 2003 .
3010 2004 .
;  
*proc print data=have; *run;
*proc sort data=have; *by gvkey yeardt; *run;

proc expand data=have out=want 
            method=step EXTRAPOLATE;
 by gvkey notsorted;
 id yeardt;
 var shrcd;
run;
proc print data=want; run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2023 16:24:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fill-in-missing-values-with-the-previous-values-for-panel/m-p/908240#M358457</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2023-12-15T16:24:08Z</dc:date>
    </item>
    <item>
      <title>Re: fill in missing values with the previous values for panel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/fill-in-missing-values-with-the-previous-values-for-panel/m-p/908248#M358458</link>
      <description>&lt;P&gt;You can use the UPDATE statement to implement last observation carried forward.&amp;nbsp; To prevent it from applying to the other variables just re-read the observation without the ones you do want carried forward.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  update have(obs=0) have;
  by gvkey;
  set have(drop=shrcd);
  output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to move values backwards in time then you will need a different method.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2023 16:35:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/fill-in-missing-values-with-the-previous-values-for-panel/m-p/908248#M358458</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-15T16:35:38Z</dc:date>
    </item>
  </channel>
</rss>

