<?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: Filling missing datadate in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/695995#M212485</link>
    <description>I have edited the main questions. By using the code, I am getting missing values filled but not the way I want. For example&lt;BR /&gt;I want something like this&lt;BR /&gt;1002 2005 20060131&lt;BR /&gt;1002 2006 .20070131..&lt;BR /&gt;But I am getting&lt;BR /&gt;1002 2005 20060131&lt;BR /&gt;1002 2006 .20340131..</description>
    <pubDate>Mon, 02 Nov 2020 16:54:37 GMT</pubDate>
    <dc:creator>abdulla</dc:creator>
    <dc:date>2020-11-02T16:54:37Z</dc:date>
    <item>
      <title>Filling missing datadate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/695839#M212394</link>
      <description>&lt;P&gt;Hi, I have some missing datadate. How to fill in the missing date&lt;/P&gt;&lt;P&gt;Gvkey&amp;nbsp; fyear&amp;nbsp; datadate&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; 2007&amp;nbsp; &amp;nbsp;20071231&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; 2008&amp;nbsp; &amp;nbsp; .....&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; 2009&amp;nbsp; &amp;nbsp;&amp;nbsp;20091231&lt;/P&gt;&lt;P&gt;1002&amp;nbsp; &amp;nbsp; 2005&amp;nbsp; &amp;nbsp;20060131&lt;/P&gt;&lt;P&gt;1002&amp;nbsp; &amp;nbsp; 2006&amp;nbsp; &amp;nbsp; .....&lt;/P&gt;&lt;P&gt;1002&amp;nbsp; &amp;nbsp; 2007&amp;nbsp; &amp;nbsp; 20080131&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;update have(obs=0) have;&lt;BR /&gt;by gvkey fyear;&lt;BR /&gt;output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above code doesn't work&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the following result&lt;/P&gt;&lt;P&gt;Gvkey&amp;nbsp; fyear&amp;nbsp; datadate&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; 2007&amp;nbsp; &amp;nbsp;20071231&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; 2008&amp;nbsp; &amp;nbsp; 20081231.....&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; 2009&amp;nbsp; &amp;nbsp;&amp;nbsp;20091231&lt;/P&gt;&lt;P&gt;1002&amp;nbsp; &amp;nbsp; 2005&amp;nbsp; &amp;nbsp;20060131&lt;/P&gt;&lt;P&gt;1002&amp;nbsp; &amp;nbsp; 2006&amp;nbsp; &amp;nbsp; .20070131....&lt;/P&gt;&lt;P&gt;1002&amp;nbsp; &amp;nbsp; 2007&amp;nbsp; &amp;nbsp; 20080131&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, It is basically the year will change, not the month and day. Datadate is a numeric value&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2020 16:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/695839#M212394</guid>
      <dc:creator>abdulla</dc:creator>
      <dc:date>2020-11-02T16:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing datadate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/695840#M212395</link>
      <description>&lt;P&gt;What should be the value for 2008?&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2020 07:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/695840#M212395</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-11-02T07:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing datadate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/695841#M212396</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/260675"&gt;@abdulla&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show what the data set should look like after the values are populated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is datadate a numeric variable (SAS date) or a character variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are the rules / logic on how to decide what value should be used for datadate?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2020 07:48:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/695841#M212396</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2020-11-02T07:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing datadate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/695847#M212401</link>
      <description>&lt;P&gt;Hi Amir, It should fill the gap based on the missing observations between two date variables or gap can be in the last or first observations or in any place by gvkey and fyear(datadate only)&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2020 08:23:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/695847#M212401</guid>
      <dc:creator>abdulla</dc:creator>
      <dc:date>2020-11-02T08:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing datadate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/695974#M212476</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/260675"&gt;@abdulla&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I've understood correctly, the value in datadate should be one more year than the last datadate; it does not need any other column. Please let me know if this not the correct understanding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ideally, dates are better stored as numeric in SAS, as they are easier to deal with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However based on what you have, you can try the following code.&lt;/P&gt;
&lt;P&gt;The first data step sets up the data, I have added some more rows at the end so that there are multiple consecutive blank datadate values.&lt;/P&gt;
&lt;P&gt;The second data step has the logic to fill in the gaps.&lt;/P&gt;
&lt;P&gt;You have to consider what should happen if the first row has a blank datadate value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   infile datalines truncover;

   input
      gvkey    : $char4.
      fyear    : $char4.
      datadate : $char8.
   ;

   datalines;
1001    2007   20071231
1001    2008
1001    2009   20091231
1002    2005   20060131
1001    2006   
1001    2007   20080131
1001    2007   
1001    2007   
1001    2007   
;


data want(drop = previous_datadate);
   set have;

   length previous_datadate $ 8;
   retain previous_datadate;

   if missing(datadate) then
      datadate = cats(input(substr(previous_datadate,1,4),8.) + 1, substr(previous_datadate,5));

   previous_datadate = datadate;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2020 15:22:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/695974#M212476</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2020-11-02T15:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing datadate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/695987#M212480</link>
      <description>Amir,&lt;BR /&gt;I have made some changes in my data. Could you please check again? The above code is not giving me the correct answer.</description>
      <pubDate>Mon, 02 Nov 2020 16:33:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/695987#M212480</guid>
      <dc:creator>abdulla</dc:creator>
      <dc:date>2020-11-02T16:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing datadate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/695993#M212483</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/260675"&gt;@abdulla&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I cannot see your new data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show your new data with the new results you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show the log with any errors using the "Insert Code" icon when posting it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2020 16:51:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/695993#M212483</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2020-11-02T16:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing datadate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/695995#M212485</link>
      <description>I have edited the main questions. By using the code, I am getting missing values filled but not the way I want. For example&lt;BR /&gt;I want something like this&lt;BR /&gt;1002 2005 20060131&lt;BR /&gt;1002 2006 .20070131..&lt;BR /&gt;But I am getting&lt;BR /&gt;1002 2005 20060131&lt;BR /&gt;1002 2006 .20340131..</description>
      <pubDate>Mon, 02 Nov 2020 16:54:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/695995#M212485</guid>
      <dc:creator>abdulla</dc:creator>
      <dc:date>2020-11-02T16:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing datadate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/696010#M212489</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/260675"&gt;@abdulla&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please respond to each point and number your three responses accordingly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) I understand &lt;SPAN&gt;the value in datadate should be one more year than the last datadate; it does not need any other column. Please let me know if this is correct, if not then please explain.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2) You are showing dots ('.') in your input data and output data, is that really what your input data is like (with dots, e.g. ".....") and is that really what you want your output data to look like (with dots, e.g. ".20070131..")?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3) I removed the dots and used the data in the following code and got the results shown further below. Please copy and paste the below code and run it in SAS. Check the "have" data set to confirm it looks correct or not. If "have" is correct, then let us know if the results are what you want and share your results - all rows, including headers.&lt;/SPAN&gt;&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 truncover;

   input
      gvkey    : $char4.
      fyear    : $char4.
      datadate : $char8.
   ;

   datalines;
1001    2007   20071231
1001    2008   
1001    2009   20091231
1002    2005   20060131
1002    2006   
1002    2007   20080131
;


data want(drop = previous_datadate);
   set have;

   length previous_datadate $ 8;
   retain previous_datadate;

   if missing(datadate) then
      datadate = cats(input(substr(previous_datadate,1,4),8.) + 1, substr(previous_datadate,5));

   previous_datadate = datadate;
run;

proc print data =  want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Obs    gvkey    fyear    datadate

 1     1001     2007     20071231
 2     1001     2008     20081231
 3     1001     2009     20091231
 4     1002     2005     20060131
 5     1002     2006     20070131
 6     1002     2007     20080131
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2020 18:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-datadate/m-p/696010#M212489</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2020-11-02T18:13:05Z</dc:date>
    </item>
  </channel>
</rss>

