<?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: Date Imputation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-Imputation/m-p/673572#M202661</link>
    <description>thank you</description>
    <pubDate>Thu, 30 Jul 2020 21:06:43 GMT</pubDate>
    <dc:creator>honeyblue</dc:creator>
    <dc:date>2020-07-30T21:06:43Z</dc:date>
    <item>
      <title>Date Imputation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Imputation/m-p/673033#M202379</link>
      <description>&lt;P&gt;data date;&lt;BR /&gt;input sdate $10.;&lt;BR /&gt;datalines;&lt;BR /&gt;1990&lt;BR /&gt;5 12 2001&lt;BR /&gt;10 10 2010&lt;BR /&gt;8 2018&lt;BR /&gt;1990&lt;BR /&gt;20 1 2017&lt;BR /&gt;12 2016&lt;BR /&gt;&lt;BR /&gt;5 2017&lt;BR /&gt;15 12 2017&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;I want 2 variables which are in bold with the below conditons&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;New date= variable&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;if day is missing then set to 15&lt;BR /&gt;if day and month missing then set to january 01&lt;BR /&gt;if day,month &amp;amp; year are missing then set to today's date&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Abbreviation = variable&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;if day is missing then set to D&lt;BR /&gt;if day and month missing then set to M&lt;BR /&gt;if day,month &amp;amp; year are missing then set to Y&lt;BR /&gt;Create brthdtc and dtcflag variables by using day, month &amp;amp; year variables.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2020 03:38:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Imputation/m-p/673033#M202379</guid>
      <dc:creator>honeyblue</dc:creator>
      <dc:date>2020-07-29T03:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: Date Imputation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Imputation/m-p/673034#M202380</link>
      <description>&lt;P&gt;Count the number of "words" and then adjust from there.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  dtcflag = char('YMD ',countw(sdate)+1);
  select (dtcflag);
    when (' ') brthdtc = input(sdate,ddmmyy10.);
    when ('D') brthdtc = input('15 '||sdate,ddmmyy10.);
    when ('M') brthdtc = input('01 01 '||sdate,ddmmyy10.);
    otherwise brthdtc=date();
  end;
  format brthdtc date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    sdate         dtcflag      brthdtc

  1    1990             M       01JAN1990
  2    5 12 2001                05DEC2001
  3    10 10 2010               10OCT2010
  4    8 2018           D       15AUG2018
  5    1990             M       01JAN1990
  6    20 1 2017                20JAN2017
  7    12 2016          D       15DEC2016
  8                     Y       28JUL2020
  9    5 2017           D       15MAY2017
 10    15 12 2017               15DEC2017
&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jul 2020 03:47:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Imputation/m-p/673034#M202380</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-29T03:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: Date Imputation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Imputation/m-p/673343#M202550</link>
      <description>&lt;P&gt;Can you please explain in details step by step&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank You&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jul 2020 02:59:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Imputation/m-p/673343#M202550</guid>
      <dc:creator>honeyblue</dc:creator>
      <dc:date>2020-07-30T02:59:56Z</dc:date>
    </item>
    <item>
      <title>Re: Date Imputation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Imputation/m-p/673345#M202551</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  dtcflag = char('YMD ',countw(sdate)+1);
  select (dtcflag);
    when (' ') brthdtc = input(sdate,ddmmyy10.);
    when ('D') brthdtc = input('15 '||sdate,ddmmyy10.);
    when ('M') brthdtc = input('01 01 '||sdate,ddmmyy10.);
    otherwise brthdtc=date();
  end;
  format brthdtc date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The COUNTW() function counts the number of words.&amp;nbsp; So you should get 0,1,2 or 3 words from your string.&amp;nbsp; The CHAR() function returns the character in the position specified.&amp;nbsp; Positions count from 1 so you need to add one to the number of words in case there are no words in the string.&amp;nbsp; So when there are no words you take the first character, Y.&lt;/P&gt;
&lt;P&gt;The SELECT statement is a multi way branching tools. So based on whether the flag is one of the four possible value a different statement is called.&lt;/P&gt;
&lt;P&gt;When you have no words use today's date.&lt;/P&gt;
&lt;P&gt;When you have one word prefix the string with 01 01 and convert it to a date.&lt;/P&gt;
&lt;P&gt;When you have two words prefix the string with 15 and convert it to a data.&lt;/P&gt;
&lt;P&gt;When you have three words just convert the string as it is to a date.&lt;/P&gt;
&lt;P&gt;The DDMMYY informat reads strings in DMY order and converts them into date values.&lt;/P&gt;
&lt;P&gt;The FORMAT statement attaches the DATE format to the variable so the number of days stored in it will print so that humans can understand it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jul 2020 03:24:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Imputation/m-p/673345#M202551</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-30T03:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: Date Imputation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Imputation/m-p/673572#M202661</link>
      <description>thank you</description>
      <pubDate>Thu, 30 Jul 2020 21:06:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Imputation/m-p/673572#M202661</guid>
      <dc:creator>honeyblue</dc:creator>
      <dc:date>2020-07-30T21:06:43Z</dc:date>
    </item>
  </channel>
</rss>

