<?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: how to fill in a missing year &amp;quot;until end of the observed time&amp;quot; by creating a dummy var in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-fill-in-a-missing-year-quot-until-end-of-the-observed/m-p/821769#M324448</link>
    <description>&lt;P&gt;Use a self-merge with lookahead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE;
	INPUT  YEAR ID $ NUMBER;
    CARDS;
 2017 a   1
 2018 a   1
 2020 a   1
 2016 b   1
 2020 b   1
 2018 c   1
 2020 c   1
 2016 d   1
 2018 e   1
RUN;
data want (drop=nxt_:);
  merge have
        have (firstobs=2 keep=year id rename=(year=nxt_yr id=nxt_id));
  if nxt_id^=id then nxt_yr=2021;
  do year=year to nxt_yr-1;
    output;
    number=0;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 06 Jul 2022 03:36:48 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-07-06T03:36:48Z</dc:date>
    <item>
      <title>how to fill in a missing year "until end of the observed time" by creating a dummy variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-fill-in-a-missing-year-quot-until-end-of-the-observed/m-p/821722#M324414</link>
      <description>&lt;P&gt;Hello SAS experts,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have already asked a&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-fill-in-missing-year-and-create-dummy-equal-zero-at-the/td-p/820942" target="_self"&gt; similar question&lt;/A&gt; previously.&lt;/P&gt;&lt;P&gt;My previous question is how&amp;nbsp;&lt;SPAN&gt;to fill in missing year&amp;nbsp;and create a dummy=0 by id.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;But if I would like to add one more criteria: for those who only have 1 record id, giving the number variable as "zero" if it didn't have any following record until the observed year.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, id=d, it only has 2016 record. I would like to have it has dummy variable until the end of the observed year (2020).&lt;/P&gt;&lt;P&gt;Can anyone give me a hand?&lt;/P&gt;&lt;P&gt;Many thanks in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA HAVE;
	INPUT  YEAR ID $ NUMBER;
    CARDS;
 2017 a   1
 2018 a   1
 2020 a   1
 2016 b   1
 2020 b   1
 2018 c   1
 2020 c   1&lt;BR /&gt; 2016 d   1&lt;BR /&gt; 2018 e   1
;
RUN;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wish my final data look like below. Many thanks for the advice in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2017&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;2018&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;2019&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; 0&lt;BR /&gt;2020&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;2016&amp;nbsp; &amp;nbsp; b&amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;2017&amp;nbsp; &amp;nbsp; b&amp;nbsp; &amp;nbsp; 0&lt;BR /&gt;2018&amp;nbsp; &amp;nbsp; b&amp;nbsp; &amp;nbsp; 0&lt;BR /&gt;2019&amp;nbsp; &amp;nbsp; b&amp;nbsp; &amp;nbsp; 0&lt;BR /&gt;2020&amp;nbsp; &amp;nbsp; b&amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;2018&amp;nbsp; &amp;nbsp; c&amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;2019&amp;nbsp; &amp;nbsp; c&amp;nbsp; &amp;nbsp; 0&lt;BR /&gt;2020&amp;nbsp; &amp;nbsp; c&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2016&amp;nbsp; &amp;nbsp; d&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2017&amp;nbsp; &amp;nbsp; d&amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2018&amp;nbsp; &amp;nbsp; d&amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2019&amp;nbsp; &amp;nbsp;d&amp;nbsp; &amp;nbsp; 0&amp;nbsp;&lt;/P&gt;&lt;P&gt;2020&amp;nbsp; d&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2018&amp;nbsp; &amp;nbsp;e&amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2019&amp;nbsp; &amp;nbsp;e&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2019&amp;nbsp; &amp;nbsp;e&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2020&amp;nbsp; e&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2022 22:50:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-fill-in-a-missing-year-quot-until-end-of-the-observed/m-p/821722#M324414</guid>
      <dc:creator>chimei0403</dc:creator>
      <dc:date>2022-07-05T22:50:04Z</dc:date>
    </item>
    <item>
      <title>Re: how to fill in a missing year "until end of the observed time" by creating a dummy var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-fill-in-a-missing-year-quot-until-end-of-the-observed/m-p/821723#M324415</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have noprint;
table year*id / out=want sparse;
weight number;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does this work or give you too many categories? If it's too much then you need to use PRELOADFMT option instead typically. You can probably find a workaround as it's numeric/year.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.lexjansen.com/nesug/nesug11/cc/cc29.pdf" target="_blank"&gt;https://www.lexjansen.com/nesug/nesug11/cc/cc29.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2022 21:25:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-fill-in-a-missing-year-quot-until-end-of-the-observed/m-p/821723#M324415</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-05T21:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: how to fill in a missing year "until end of the observed time" by creating a dummy var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-fill-in-a-missing-year-quot-until-end-of-the-observed/m-p/821756#M324435</link>
      <description>&lt;P&gt;The pseudo code is this: &lt;BR /&gt;1) make a one-variable data set with variable YEAR containing all consecutive years just once per year&lt;BR /&gt;2) left join it to your dataset by year (this will create gaps in ID and NUMBER for the added observations)&lt;BR /&gt;3) use Last Observation Carry Forward (LOCF) on ID to fill in the gaps&lt;BR /&gt;4) if NUMBER is missing set it to zero. &lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2022 01:33:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-fill-in-a-missing-year-quot-until-end-of-the-observed/m-p/821756#M324435</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2022-07-06T01:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to fill in a missing year "until end of the observed time" by creating a dummy var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-fill-in-a-missing-year-quot-until-end-of-the-observed/m-p/821758#M324437</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;, Thank you so much for the advice! The following codes work but create number=0 for those years before index year.&lt;/P&gt;&lt;P&gt;Since I am really at the beginner level of SAS,&amp;nbsp;&lt;SPAN&gt;PRELOADFMT seems hard for me to fit in the solution.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;However, what I can think of is: create a series number by id in the have data file, run the program you advice, and then delete those series number are missing.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Again, thank you so much. I feel this SAS forum is super supportive!!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2022 01:42:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-fill-in-a-missing-year-quot-until-end-of-the-observed/m-p/821758#M324437</guid>
      <dc:creator>chimei0403</dc:creator>
      <dc:date>2022-07-06T01:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to fill in a missing year "until end of the observed time" by creating a dummy var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-fill-in-a-missing-year-quot-until-end-of-the-observed/m-p/821759#M324438</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/235176"&gt;@pink_poodle&lt;/a&gt;&amp;nbsp;Thank you so much for the advice. I will try it tomorrow!!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2022 01:44:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-fill-in-a-missing-year-quot-until-end-of-the-observed/m-p/821759#M324438</guid>
      <dc:creator>chimei0403</dc:creator>
      <dc:date>2022-07-06T01:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to fill in a missing year "until end of the observed time" by creating a dummy var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-fill-in-a-missing-year-quot-until-end-of-the-observed/m-p/821769#M324448</link>
      <description>&lt;P&gt;Use a self-merge with lookahead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE;
	INPUT  YEAR ID $ NUMBER;
    CARDS;
 2017 a   1
 2018 a   1
 2020 a   1
 2016 b   1
 2020 b   1
 2018 c   1
 2020 c   1
 2016 d   1
 2018 e   1
RUN;
data want (drop=nxt_:);
  merge have
        have (firstobs=2 keep=year id rename=(year=nxt_yr id=nxt_id));
  if nxt_id^=id then nxt_yr=2021;
  do year=year to nxt_yr-1;
    output;
    number=0;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Jul 2022 03:36:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-fill-in-a-missing-year-quot-until-end-of-the-observed/m-p/821769#M324448</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-07-06T03:36:48Z</dc:date>
    </item>
  </channel>
</rss>

