<?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 values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911516#M359429</link>
    <description>&lt;P&gt;What should the result be when your rules suggest a conflict?&amp;nbsp; For example, what if column X contains:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;.
.
.
1
.
.
.
2
3
.
.&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 14 Jan 2024 12:13:16 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2024-01-14T12:13:16Z</dc:date>
    <item>
      <title>Filling missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911513#M359428</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Happy New Year!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;For each non-missing value in Column X, I want to fill the previous 5 and the next 1 observation with this non-missing value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In short, I have the following dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Column X&amp;nbsp;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;1 (non-missing)&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to have the following output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Column X&amp;nbsp;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;1 (previous 5 missing values are filled our with non-missing)&lt;/P&gt;&lt;P&gt;1 (previous 5 missing values are filled our with non-missing)&lt;/P&gt;&lt;P&gt;1 (previous 5 missing values are filled our with non-missing)&lt;/P&gt;&lt;P&gt;1 (previous 5 missing values are filled our with non-missing)&lt;/P&gt;&lt;P&gt;1 (previous 5 missing values are filled our with non-missing)&lt;/P&gt;&lt;P&gt;1 (non-missing)&lt;/P&gt;&lt;P&gt;1 (next one missing value is filled out with non-missing)&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jan 2024 10:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911513#M359428</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2024-01-14T10:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911516#M359429</link>
      <description>&lt;P&gt;What should the result be when your rules suggest a conflict?&amp;nbsp; For example, what if column X contains:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;.
.
.
1
.
.
.
2
3
.
.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 Jan 2024 12:13:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911516#M359429</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2024-01-14T12:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911517#M359430</link>
      <description>Thanks,&lt;BR /&gt;&lt;BR /&gt;In this case:&lt;BR /&gt;&lt;BR /&gt;1&lt;BR /&gt;1&lt;BR /&gt;1&lt;BR /&gt;1 (non-missing)&lt;BR /&gt;1&lt;BR /&gt;2&lt;BR /&gt;2&lt;BR /&gt;2 (non-missing)&lt;BR /&gt;3 (non-missing)&lt;BR /&gt;3&lt;BR /&gt;.&lt;BR /&gt;&lt;BR /&gt;Also, there are only a few conflicting cases.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 14 Jan 2024 12:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911517#M359430</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2024-01-14T12:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911518#M359431</link>
      <description>&lt;P&gt;In order to write code that works, there must be &lt;FONT color="#FF0000"&gt;no&lt;/FONT&gt; conflicting cases in the description ... or you describe clearly and unambiguously what to do when there are conflicts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, how large is the REAL data set you are working with (number of rows, number of columns)? The solution will have to scale well to the real data set and not take forever and use up all disk space available; writing code on your 10 lines or so may or may not produce scalable code.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jan 2024 12:31:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911518#M359431</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-01-14T12:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911519#M359432</link>
      <description>I just checked the data. There are no conflicts.&lt;BR /&gt;The only important issue is I need to fill out the missing values. That is it.</description>
      <pubDate>Sun, 14 Jan 2024 12:31:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911519#M359432</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2024-01-14T12:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911520#M359433</link>
      <description>&lt;P&gt;What is the rule for retaining 1 &lt;U&gt;once&lt;/U&gt; after the non-missing 1, and from then on have &lt;U&gt;two&lt;/U&gt; "look-aheads" with value 2?&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jan 2024 12:47:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911520#M359433</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-01-14T12:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911522#M359434</link>
      <description>&lt;P&gt;I would like to provide additional details to clarify my question. My apologies for any inconvenience caused.&lt;/P&gt;&lt;P&gt;My dataset comprises various events, all recorded in Column X. This column contains a value when an event occurs; if no event occurs, Column X is left blank. For a more comprehensive understanding, please refer to the following data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Column X&lt;/P&gt;&lt;P&gt;01.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;02.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;03.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;04.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;05.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;06.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;07.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp;&lt;/P&gt;&lt;P&gt;08.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;09.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this dataset, an event is recorded on 07.01.2022, marked as '1' in Column X. Each event is uniquely identified, such as the second event being marked as '2' on its respective date.&lt;/P&gt;&lt;P&gt;I am looking to create an 'event window' for each event, encompassing 5 days prior to and 1 day after the event date. Specifically, I aim to generate data output as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Column X&lt;/P&gt;&lt;P&gt;01.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;02.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;(pre-event window)&lt;/P&gt;&lt;P&gt;03.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;(pre-event window)&lt;/P&gt;&lt;P&gt;04.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;(pre-event window)&lt;/P&gt;&lt;P&gt;05.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;(pre-event window)&lt;/P&gt;&lt;P&gt;06.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 (pre-event window)&lt;/P&gt;&lt;P&gt;07.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 (event date)&lt;/P&gt;&lt;P&gt;08.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 (post-event window)&lt;/P&gt;&lt;P&gt;09.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please be aware that using the date column presents challenges. This is due to some events occurring on Fridays, resulting in the next available day being Monday.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In terms of handling conflicts: if another event occurs 3 days before a given event, we should only use observations up to the date of this preceding event. Additionally, if two events happen on consecutive dates, we will exclude the post-event window and include only the days leading up to the first event.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope it is now clear.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks everyone.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jan 2024 13:45:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911522#M359434</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2024-01-14T13:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911523#M359435</link>
      <description>&lt;P&gt;I would like to provide additional details to clarify my question. My apologies for any inconvenience caused.&lt;/P&gt;&lt;P&gt;My dataset comprises various events, all recorded in Column X. This column contains a value when an event occurs; if no event occurs, Column X is left blank. For a more comprehensive understanding, please refer to the following data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Column X&lt;/P&gt;&lt;P&gt;01.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;02.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;03.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;04.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;05.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;06.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;07.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp;&lt;/P&gt;&lt;P&gt;08.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;09.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this dataset, an event is recorded on 07.01.2022, marked as '1' in Column X. Each event is uniquely identified, such as the second event being marked as '2' on its respective date.&lt;/P&gt;&lt;P&gt;I am looking to create an 'event window' for each event, encompassing 5 days prior to and 1 day after the event date. Specifically, I aim to generate data output as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Column X&lt;/P&gt;&lt;P&gt;01.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;02.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;(pre-event window)&lt;/P&gt;&lt;P&gt;03.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;(pre-event window)&lt;/P&gt;&lt;P&gt;04.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;(pre-event window)&lt;/P&gt;&lt;P&gt;05.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;(pre-event window)&lt;/P&gt;&lt;P&gt;06.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 (pre-event window)&lt;/P&gt;&lt;P&gt;07.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 (event date)&lt;/P&gt;&lt;P&gt;08.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 (post-event window)&lt;/P&gt;&lt;P&gt;09.01.2022&amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please be aware that using the date column presents challenges. This is due to some events occurring on Fridays, resulting in the next available day being Monday.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In terms of handling conflicts: if another event occurs 3 days before a given event, we should only use observations up to the date of this preceding event. Additionally, if two events happen on consecutive dates, we will exclude the post-event window and include only the days leading up to the first event.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have about 7 million rows in the data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope it is now clear.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks everyone.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jan 2024 13:47:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911523#M359435</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2024-01-14T13:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911524#M359436</link>
      <description>&lt;P&gt;You can do this nicely with &lt;STRONG&gt;PROC TIMEDATA&lt;/STRONG&gt;. &lt;BR /&gt;That's because the entire time series (of the by-group) is loaded into memory. That way, you can easily navigate the time series (singular or plural) and retrieve values. If you are at time "t", you can very easily retrieve value from [t-7] or from [t+3]. Very handy. So you can look backwards and also forwards. The latter is not always easy in a data step.&lt;/P&gt;
&lt;P&gt;For multiple time series, it's like being in a 2-dimensional matrix and being able to address each cell.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;PROC TIMEDATA is the data step for time series !!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;(you need SAS Econometrics or SAS/ETS to have this procedure available)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL class="lia-list-style-type-square"&gt;
&lt;LI&gt;Data Step for Timeseries: part 1, Overview&lt;BR /&gt;by chwell&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Data-Step-for-Timeseries-part-1-Overview/ta-p/878419" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Data-Step-for-Timeseries-part-1-Overview/ta-p/878419&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Data Step for Timeseries: part 2, BY Group Processing&lt;BR /&gt;by chwell&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Data-Step-for-Timeseries-part-2-BY-Group-Processing/ta-p/908380" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Data-Step-for-Timeseries-part-2-BY-Group-Processing/ta-p/908380&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;BR, Koen&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jan 2024 14:37:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911524#M359436</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-01-14T14:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911528#M359437</link>
      <description>&lt;P&gt;First let's assume those ambiguous date strings are in DMY order since if they are in MDY order none of them are within 5 days of each other.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input date :ddmmyy. X ;
  format date yymmdd10.;
cards;
01.01.2022 .
02.01.2022 .
03.01.2022 .
04.01.2022 .
05.01.2022 .
06.01.2022 .
07.01.2022 1 
08.01.2022 .
09.01.2022 .
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since there are a limited number of days you need to check you can just use a temporary array to solve this problem.&amp;nbsp; Use the date value as the index into the array. Since the array statement wants integer constants you can use macro code to generate the lower and upper bounds.&amp;nbsp; Just pick a range you know is at least as large as your actual date range.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  array all[%sysfunc(mdy(1,1,2022)):%sysfunc(mdy(12,31,2022))] _temporary_;
  if _n_=1 then do until(eof1);
    set have end=eof1;
    where not missing(x);
    do date=date-5 to date+1;
      all[date]=X;
    end;
  end;
  set have ;
  x=coalesce(x,all[date]);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Result&lt;/P&gt;
&lt;PRE&gt;Obs          date    X

 1     2022-01-01    .
 2     2022-01-02    1
 3     2022-01-03    1
 4     2022-01-04    1
 5     2022-01-05    1
 6     2022-01-06    1
 7     2022-01-07    1
 8     2022-01-08    1
 9     2022-01-09    .

&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 Jan 2024 16:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911528#M359437</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-01-14T16:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911544#M359443</link>
      <description>&lt;P&gt;So, per your revised sample data, if you have a variable DATE for the entire history of events and non-events, and the variable X, then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
  date=_n_+'01sep2023'd;  format date date9.;
  input x @@;
datalines;  /*X values placed with at least 6 missings between them */
. . . . . 1 .
. . . . . . . . 2 .
. . . . . . 3 . .
run;

data want (drop=_:);
  merge have
        have (firstobs=6 keep=x rename=(x=_x_advance));

  if _x_advance^=. then do;
    _countdown=5;
    _x_replace=_x_advance;
  end;
  retain _x_replace _countdown;

  x=  coalesce(x,_x_replace,lag(x));
  if _countdown&amp;gt;0 then _countdown=_countdown-1;
  else if _countdown=0 then call missing(_x_replace);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This works as long as you have 6 or more missing X's between events.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2024 05:58:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911544#M359443</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-01-15T05:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911546#M359445</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x;
cards;
.
.
.
1
.
.
.
2
3
.
.
;
data have;
 set have;
 id+1;
run;
data temp1;
 set have;
 retain next;
 if not missing(x) then next=x;
 if missing(x) then n+1;
  else n=0;
run;
data temp1;
 set temp1;
 if n ne 1 then call missing(next);
run;
/******************/
proc sort data=have out=temp2;
by descending id;
run;
data temp2;
 set temp2;
 retain lag;
 if not missing(x) then lag=x;
 if missing(x) then n+1;
  else n=0;
run;
data temp2;
 set temp2;
 if n not in (1:5) then call missing(lag);
run;
proc sort data=temp2;
by  id;
run;
/*******************/
data want;
 merge temp1(keep=x next) temp2(keep=x lag);
want=coalesce(x,next,lag);
drop next lag;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Jan 2024 08:24:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911546#M359445</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-01-15T08:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: Filling missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911549#M359446</link>
      <description>&lt;P&gt;Thank you! It is also correct!&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2024 09:09:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-missing-values/m-p/911549#M359446</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2024-01-15T09:09:26Z</dc:date>
    </item>
  </channel>
</rss>

