<?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: Best method to calculate correct age with different DOB forms in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Best-method-to-calculate-correct-age-with-different-DOB-forms/m-p/723732#M224642</link>
    <description>&lt;P&gt;If the SAS variable is a date then it is a numeric value. That numeric value is used for any purpose for matching. The Format used to display it in different data sets makes no difference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I highly doubt that the values in your DS2 are dates. Or you need to show Proc Contents for that data set.&lt;/P&gt;
&lt;P&gt;When I do this:&lt;/P&gt;
&lt;PRE&gt;data junk;
   input x;
   put x= date9. x= mmddyy10. x=yymmdd10.;
datalines;
30427
30607
39465
19375
42183
;&lt;/PRE&gt;
&lt;P&gt;I get results like&lt;/P&gt;
&lt;PRE&gt;x=22APR2043 x=04/22/2043 x=2043-04-22
x=19OCT2043 x=10/19/2043 x=2043-10-19
x=19JAN2068 x=01/19/2068 x=2068-01-19
x=17JAN2013 x=01/17/2013 x=2013-01-17
x=29JUN2075 x=06/29/2075 x=2075-06-29
&lt;/PRE&gt;
&lt;P&gt;Which makes me very suspicious that the values except the 17Jan2013 are actually Excel numeric dates and that you need to check the results of Proc Import closely. Or use a different approach to reading the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing with Date values is to always assign a date format to the values so they make sense to people.&lt;/P&gt;
&lt;P&gt;The other is to read date values with a proper Informat. Here is an example of reading two different variables from text in different formats and then matching the values even though the variables have different formats.&lt;/P&gt;
&lt;PRE&gt;data junk1;
  input x :mmddyy10.;
  format x mmddyy10.;
datalines;
01202010
02152013
;

data junk2;
  input y yymmdd10.;
  format y yymmdd10.;
datalines;
20100120
20130215
;

proc sql;
   create table example as
   select a.x, b.y
   from junk1 as a
        left join
        junk2 as b
        on a.x=b.y
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;I think you need to read the log a bit closer after running this:&lt;/P&gt;
&lt;PRE&gt;    Data Opera.Arias_view_1;
       Set Opera.Arias_view_1(rename = (DOB=DOBNUM));
       DOB = input(DOBNUM, $11.);
        drop DOBNUM;
    run;&lt;/PRE&gt;
&lt;P&gt;and you should keep dobnum for comparison.&lt;/P&gt;
&lt;P&gt;If the DOB is an actual date numeric value then input(DOBNUM, $11.) will throw some messages because INPUT expects character values and the conversion is likely way wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I strongly suspect you need to go back to the import step and read the data properly using date informats with a data step and/or seriously fixing one or more Excel files.&lt;/P&gt;
&lt;P&gt;Please run Proc Contents on BOTH of those sets a show the results for all of the variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Mar 2021 23:59:52 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-03-04T23:59:52Z</dc:date>
    <item>
      <title>Best method to calculate correct age with different DOB forms</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-to-calculate-correct-age-with-different-DOB-forms/m-p/723711#M224628</link>
      <description>&lt;P&gt;I have asked variants of this question before.&amp;nbsp; It deals with having different formats for date of birth.&amp;nbsp; DOB is then used to calculate age.&amp;nbsp; I have received useful information on this subject from Tom and Jim.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this is the current issue.&amp;nbsp; I have two data sets (containing contact tracing data) DS1 has DOB in the following format (I use Proc import to move these data sets from excel xlsx files) - the values in the SAS dataset are like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;03/31/1997&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10/25/1993&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 05/16/1998&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 07/25/2019&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01/20/1977&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . . .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;and so on&amp;nbsp; (79,000 obs but not all have a populated DOB)&lt;/P&gt;&lt;P&gt;the type is numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then in dataset two, DS2, the DOB (after the Proc import) is in SAS date form like&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30427&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30607&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;39465&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;19375&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 42183&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . . .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and so on&amp;nbsp; (80,200 obs&amp;nbsp;but not all have a populated DOB)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One question is what is the correct method to follow to get these fields in the same format?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before I can merge these two data sets I have to consistently define the DOB. I have tried it like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; So I have been trying to change DS1 to DS2 format like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Data Opera.Arias_view_1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Set Opera.Arias_view_1(rename = (DOB=DOBNUM));&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DOB = input(DOBNUM, $11.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drop DOBNUM;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; run;&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;Unfortunately,&amp;nbsp; the resulting DOB field has values like the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1360&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -677&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2175&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -178&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1950&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Obviously, incorrect.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two other datasets (case data from covid testing) that have Age fields with data like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 19&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;34&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;77&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;29&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. . .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;and so on&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to clean up the DOB fields in the contact tracing datasets and produce Age fields analogous to what is in the case datasets.&amp;nbsp; Then the cases and the contacts datasets can be merged on an ID field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;wlierman&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, 04 Mar 2021 23:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-to-calculate-correct-age-with-different-DOB-forms/m-p/723711#M224628</guid>
      <dc:creator>wklierman</dc:creator>
      <dc:date>2021-03-04T23:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: Best method to calculate correct age with different DOB forms</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-to-calculate-correct-age-with-different-DOB-forms/m-p/723727#M224639</link>
      <description>What does 30427 show as in your Excel file?&lt;BR /&gt;&lt;BR /&gt;SAS (and Excel and most software applications) actually store dates as the number of days from a specific date, in SAS that date is January 1, 1960 but Excel uses a different cutoff. Sometimes when reading a file, it will get brought in correctly and sometimes you have to correct it. The first attempt should be to just apply a date format to the variable and see how it displays. Then you can figure out if you need to actually change it in some manner.&lt;BR /&gt;&lt;BR /&gt;This should print the first 10 dob, formatted as a date. Do they match what you have in your Excel file?&lt;BR /&gt;&lt;BR /&gt;proc print data=opera.arias_view_1 (obs=10);&lt;BR /&gt;var dob;&lt;BR /&gt;format dob date9.;&lt;BR /&gt;run;&lt;BR /&gt;    &lt;BR /&gt;</description>
      <pubDate>Thu, 04 Mar 2021 23:46:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-to-calculate-correct-age-with-different-DOB-forms/m-p/723727#M224639</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-04T23:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: Best method to calculate correct age with different DOB forms</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-to-calculate-correct-age-with-different-DOB-forms/m-p/723732#M224642</link>
      <description>&lt;P&gt;If the SAS variable is a date then it is a numeric value. That numeric value is used for any purpose for matching. The Format used to display it in different data sets makes no difference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I highly doubt that the values in your DS2 are dates. Or you need to show Proc Contents for that data set.&lt;/P&gt;
&lt;P&gt;When I do this:&lt;/P&gt;
&lt;PRE&gt;data junk;
   input x;
   put x= date9. x= mmddyy10. x=yymmdd10.;
datalines;
30427
30607
39465
19375
42183
;&lt;/PRE&gt;
&lt;P&gt;I get results like&lt;/P&gt;
&lt;PRE&gt;x=22APR2043 x=04/22/2043 x=2043-04-22
x=19OCT2043 x=10/19/2043 x=2043-10-19
x=19JAN2068 x=01/19/2068 x=2068-01-19
x=17JAN2013 x=01/17/2013 x=2013-01-17
x=29JUN2075 x=06/29/2075 x=2075-06-29
&lt;/PRE&gt;
&lt;P&gt;Which makes me very suspicious that the values except the 17Jan2013 are actually Excel numeric dates and that you need to check the results of Proc Import closely. Or use a different approach to reading the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing with Date values is to always assign a date format to the values so they make sense to people.&lt;/P&gt;
&lt;P&gt;The other is to read date values with a proper Informat. Here is an example of reading two different variables from text in different formats and then matching the values even though the variables have different formats.&lt;/P&gt;
&lt;PRE&gt;data junk1;
  input x :mmddyy10.;
  format x mmddyy10.;
datalines;
01202010
02152013
;

data junk2;
  input y yymmdd10.;
  format y yymmdd10.;
datalines;
20100120
20130215
;

proc sql;
   create table example as
   select a.x, b.y
   from junk1 as a
        left join
        junk2 as b
        on a.x=b.y
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;I think you need to read the log a bit closer after running this:&lt;/P&gt;
&lt;PRE&gt;    Data Opera.Arias_view_1;
       Set Opera.Arias_view_1(rename = (DOB=DOBNUM));
       DOB = input(DOBNUM, $11.);
        drop DOBNUM;
    run;&lt;/PRE&gt;
&lt;P&gt;and you should keep dobnum for comparison.&lt;/P&gt;
&lt;P&gt;If the DOB is an actual date numeric value then input(DOBNUM, $11.) will throw some messages because INPUT expects character values and the conversion is likely way wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I strongly suspect you need to go back to the import step and read the data properly using date informats with a data step and/or seriously fixing one or more Excel files.&lt;/P&gt;
&lt;P&gt;Please run Proc Contents on BOTH of those sets a show the results for all of the variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 23:59:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-to-calculate-correct-age-with-different-DOB-forms/m-p/723732#M224642</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-04T23:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: Best method to calculate correct age with different DOB forms</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-to-calculate-correct-age-with-different-DOB-forms/m-p/723735#M224644</link>
      <description>Thank you for the research suggestions. I will follow-up and be back in touch.&lt;BR /&gt;&lt;BR /&gt;wklierman&lt;BR /&gt;</description>
      <pubDate>Fri, 05 Mar 2021 00:09:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-to-calculate-correct-age-with-different-DOB-forms/m-p/723735#M224644</guid>
      <dc:creator>wklierman</dc:creator>
      <dc:date>2021-03-05T00:09:45Z</dc:date>
    </item>
  </channel>
</rss>

