<?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 impute in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/date-impute/m-p/251992#M47719</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Dte;
input birthdate $10.;
cards;
Jan1975
1977
021978
run;
data want ;
set Dte;
format date date9.;
if length(birthdate)=4 then date=input('11JUL'!!trim(birthdate),date9.);
else if length(birthdate)=6 then date=
input(substr(birthdate,1,2)!!'JUL'!!substr(birthdate,3,4),date9.); 
else if length(birthdate)=7 then date=input('11'!!trim(birthdate),date9.); 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 24 Feb 2016 09:10:48 GMT</pubDate>
    <dc:creator>mohamed_zaki</dc:creator>
    <dc:date>2016-02-24T09:10:48Z</dc:date>
    <item>
      <title>date impute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-impute/m-p/251987#M47715</link>
      <description>&lt;P&gt;&lt;SPAN&gt;am writing dis code to check missing day &amp;amp; month &amp;nbsp;from the input below &amp;nbsp;&amp;amp; display the correct format according to the given values below,&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;the dates should be converted to ddmmmyyyy date9 format year is constant, &amp;nbsp;if day is missing then day=11 if month mssng then month=JUL&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but am getting a different output plz can u help below is my code &amp;amp; output.&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 Dte;
input birthdate $10.;
cards;
Jan1975
1977
021978
run;
&amp;nbsp;
data IMPUTE(Keep = birthdate new_bdate);
set dte; 
format day $2. month $3. New_bdate $11.;
call scan(birthdate, 1, First_Pos, First_Length);
First_Word = substrn(birthdate, First_Pos, First_Length);
call scan(birthdate, 1, Last_Pos, Last_Length);
Last_Word = substrn(birthdate, Last_Pos, Last_Length);
if length(birthdate) = 10 then length1 = 'Y';
else length1 = 'N';
if length1 = 'Y' then do;
Day = substr(birthdate,1,2);
Month = substr(birthdate,3,3);
end;
else if length1 = 'N' then do;
if (First_Pos = '1' and Last_Length = '2') then do 
Day = First_Word;
Month = 'JUL';

end;
else if (First_Pos = '1' and Last_Length = '8') then do 
Day = First_Word;
Month = Last_Word;

end;
else if (First_Pos = '1' and Last_Length = '4') then do 
Day = First_Word;
Month = 'JUL';
Year = Last_Word;
end;
if (First_Pos = '2' and Last_Length = '5') then do 
Day = '11';
Month = First_Word;

end;
else if (First_Pos = '3' and Last_Length = '4') then do 
Day = '11';
Month = First_Word;
Year = Last_Word;
end;
else if (First_Pos = '3' and Last_Length = '4') then do 
Day = '11';
Month = 'JUL';
Year = Last_Word;
end;
end;
New_bdate = Day||Month||Year;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output--&amp;gt;&lt;/P&gt;
&lt;DIV class="dgrid-header dgrid-header-row ui-widget-header"&gt;
&lt;TABLE id="dgrid_125-header" class="dgrid-row-table"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="dgrid-cell dgrid-cell-padding dgrid-column-0 field-col0 obsNumCell" tabindex="0"&gt;&amp;nbsp;&lt;/TH&gt;
&lt;TH class="dgrid-cell dgrid-cell-padding dgrid-column-1 field-col1 dgrid-sortable"&gt;
&lt;DIV class="dgrid-resize-header-container"&gt;birthdate
&lt;DIV class="dgrid-resize-handle resizeNode-1"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TH&gt;
&lt;TH class="dgrid-cell dgrid-cell-padding dgrid-column-2 field-col2 dgrid-sortable"&gt;
&lt;DIV class="dgrid-resize-header-container"&gt;New_bdate
&lt;DIV class="dgrid-resize-handle resizeNode-2"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TH&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;DIV class="dgrid-scroller"&gt;
&lt;DIV class="dgrid-content ui-widget-content"&gt;
&lt;DIV id="dgrid_125-row-0" class=" dgrid-row dgrid-row-even ui-state-default"&gt;
&lt;TABLE class="dgrid-row-table"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="dgrid-cell dgrid-cell-padding dgrid-column-0 field-col0 obsNumCell dgrid-focus"&gt;1&lt;/TD&gt;
&lt;TD class="dgrid-cell dgrid-cell-padding dgrid-column-1 field-col1"&gt;Jan1975&lt;/TD&gt;
&lt;TD class="dgrid-cell dgrid-cell-padding dgrid-column-2 field-col2"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;DIV id="dgrid_125-row-1" class=" dgrid-row dgrid-row-odd ui-state-default"&gt;
&lt;TABLE class="dgrid-row-table"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="dgrid-cell dgrid-cell-padding dgrid-column-0 field-col0 obsNumCell"&gt;2&lt;/TD&gt;
&lt;TD class="dgrid-cell dgrid-cell-padding dgrid-column-1 field-col1"&gt;1977&lt;/TD&gt;
&lt;TD class="dgrid-cell dgrid-cell-padding dgrid-column-2 field-col2"&gt;19JUN1977&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;DIV id="dgrid_125-row-2" class=" dgrid-row ui-state-default dgrid-row-even"&gt;
&lt;TABLE class="dgrid-row-table"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="dgrid-cell dgrid-cell-padding dgrid-column-0 field-col0 obsNumCell"&gt;3&lt;/TD&gt;
&lt;TD class="dgrid-cell dgrid-cell-padding dgrid-column-1 field-col1"&gt;021978&lt;/TD&gt;
&lt;TD class="dgrid-cell dgrid-cell-padding dgrid-column-2 field-col2"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HOW can i modify this code to get required output.&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>Wed, 24 Feb 2016 15:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-impute/m-p/251987#M47715</guid>
      <dc:creator>RTelang</dc:creator>
      <dc:date>2016-02-24T15:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: date impute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-impute/m-p/251990#M47717</link>
      <description>&lt;P&gt;It depends a bit, you may be able to do it just on length:&lt;/P&gt;
&lt;PRE&gt;data have;
  birthdate="Jan1975"; output;
  birthdate="1977"; output;
  birthdate="021978"; output;
run;

data want;
  set have;
  select(length(strip(upcase(birthdate))));
    when (9) new_bdate=input(birthdate,date9.);
    when (7) new_bdate=input(cats("11",birthdate),date9.);
    when (4) new_bdate=input(cats("11JUL",birthdate),date9.);
    otherwise;
  end;
  format new_bdate date9.;
run;&lt;/PRE&gt;
&lt;P&gt;Not sure what to do with the last value you gave, there is no indication of what&amp;nbsp;&lt;SPAN&gt;021978 represents. &amp;nbsp;Where is the data coming from, they should have specifications which detail the format of the data, just add where clause for each permutation of the data.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2016 09:06:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-impute/m-p/251990#M47717</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-02-24T09:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: date impute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-impute/m-p/251991#M47718</link>
      <description>it represents  ddyyyy with month missing</description>
      <pubDate>Wed, 24 Feb 2016 09:08:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-impute/m-p/251991#M47718</guid>
      <dc:creator>RTelang</dc:creator>
      <dc:date>2016-02-24T09:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: date impute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-impute/m-p/251992#M47719</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Dte;
input birthdate $10.;
cards;
Jan1975
1977
021978
run;
data want ;
set Dte;
format date date9.;
if length(birthdate)=4 then date=input('11JUL'!!trim(birthdate),date9.);
else if length(birthdate)=6 then date=
input(substr(birthdate,1,2)!!'JUL'!!substr(birthdate,3,4),date9.); 
else if length(birthdate)=7 then date=input('11'!!trim(birthdate),date9.); 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Feb 2016 09:10:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-impute/m-p/251992#M47719</guid>
      <dc:creator>mohamed_zaki</dc:creator>
      <dc:date>2016-02-24T09:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: date impute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-impute/m-p/251995#M47721</link>
      <description>&lt;P&gt;So add another condition to handle this - remember you know your data, and have specs detailing it so you will need to identify and handle any ranges within that data&amp;amp;colon;&lt;/P&gt;
&lt;PRE&gt;data have;
  birthdate="Jan1975"; output;
  birthdate="1977"; output;
  birthdate="021978"; output;
run;

data want;
  set have;
  select(length(strip(upcase(birthdate))));
    when (9) new_bdate=input(birthdate,date9.);
    when (7) new_bdate=input(cats("11",birthdate),date9.);
    when (4) new_bdate=input(cats("11JUL",birthdate),date9.);&lt;BR /&gt;    when (6) new_bdate=input(cats(substr(birthdate,1,2),"JUL",substr(birthdate,3,4)),date9.);
    otherwise;
  end;
  format new_bdate date9.;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Feb 2016 09:17:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-impute/m-p/251995#M47721</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-02-24T09:17:29Z</dc:date>
    </item>
    <item>
      <title>Re: date impute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-impute/m-p/251998#M47722</link>
      <description>&lt;P&gt;There are many rules you need consider about.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Dte;
input birthdate $10.;
cards;
Jan1975
1977
021978
;
run;
data want;
 set Dte;
 if prxmatch('/\d\d\w\w\w\d\d\d\d/',birthdate ) then new=input(birthdate,date9.);
  else if prxmatch('/\w\w\w\d\d\d\d/',birthdate ) then new=input('11'||birthdate,date9.);
   else if prxmatch('/\d\d\d\d\d\d/',birthdate ) then new=input(substr(birthdate,1,2)||'Jul'||substr(birthdate,3),date9.);
    else if prxmatch('/\d\d\d\d/',birthdate ) then new=input('11Jul'||birthdate,date9.);
format new date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Feb 2016 09:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-impute/m-p/251998#M47722</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-02-24T09:23:20Z</dc:date>
    </item>
  </channel>
</rss>

