<?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 Fixing inconsistent DOB/dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Fixing-inconsistent-DOB-dates/m-p/748611#M235108</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was given an excel sheet that has a date of birth (DOB) variable which has been recorded in the following formats:&lt;/P&gt;&lt;P&gt;49y&lt;/P&gt;&lt;P&gt;2/23/1970/49y&lt;/P&gt;&lt;P&gt;2/23/1970&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ultimately would like to remove the day to have the DOB in just month/year format (02/1970) and create a new age variable. However, I am hung up on how to even get this into a uniform date format. Any help would be greatly appreciated!&lt;/P&gt;</description>
    <pubDate>Thu, 17 Jun 2021 05:18:24 GMT</pubDate>
    <dc:creator>meghanrm</dc:creator>
    <dc:date>2021-06-17T05:18:24Z</dc:date>
    <item>
      <title>Fixing inconsistent DOB/dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fixing-inconsistent-DOB-dates/m-p/748611#M235108</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was given an excel sheet that has a date of birth (DOB) variable which has been recorded in the following formats:&lt;/P&gt;&lt;P&gt;49y&lt;/P&gt;&lt;P&gt;2/23/1970/49y&lt;/P&gt;&lt;P&gt;2/23/1970&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ultimately would like to remove the day to have the DOB in just month/year format (02/1970) and create a new age variable. However, I am hung up on how to even get this into a uniform date format. Any help would be greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jun 2021 05:18:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fixing-inconsistent-DOB-dates/m-p/748611#M235108</guid>
      <dc:creator>meghanrm</dc:creator>
      <dc:date>2021-06-17T05:18:24Z</dc:date>
    </item>
    <item>
      <title>Re: Fixing inconsistent DOB/dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fixing-inconsistent-DOB-dates/m-p/748617#M235112</link>
      <description>&lt;P&gt;I will forgo the usual comments on Excel as data-source.&lt;/P&gt;
&lt;P&gt;You need a date to calculate the dob from strings like "49y". One could use today(), but that will give wrong results, if the code is executed next year.&lt;/P&gt;
&lt;P&gt;Assuming that you are familiar with concepts of formats and informats, you could start with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   length dobString $ 20;
   input dobString;
   datalines;
49y
2/23/1970/49y
2/23/1970
;

data want;
   set have;
   
   length dob 8 years 8 helper $ 20;
   format dob mmyys7.;
   
   /* try to create a sas-date */
   dob = input(dobString, ?? mmddyy10.);
   
   if missing(dob) then do;
      /* dobString is not a sas-date */
      if countc(dobString, '/') = 0 then do;
         years = input(compress(dobString,, 'kd'), best.);
         /* the date-constant needs to replaced by the date on which the data was recorded */
         dob = intnx('years', '01Apr2021'd, years * (-1), 's');
      end;
      else do;
         helper = substr(dobString, 1, findc(dobString, '/', 'b')-1);
         dob = input(helper, ?? mmddyy10.);
      end;
   end;
   
   drop years helper;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Jun 2021 06:11:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fixing-inconsistent-DOB-dates/m-p/748617#M235112</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-06-17T06:11:53Z</dc:date>
    </item>
  </channel>
</rss>

