<?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: Calculating age using birthday that is numeric format (default 8.) and date of last visit in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807411#M318335</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294090"&gt;@Bluekeys49&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have one variable called date_of_birth that is a numeric value with default length 8.&amp;nbsp; A couple of the values are 82902 (which is August 29, 2002) and 111797 (which is November 17, 1997).&amp;nbsp; I'll be creating a second variable, date_last_visit, in which I'll need to calculate age at time of date_last_visit.&amp;nbsp; Date_last_visit will be July 4, 2022 for everyone.&amp;nbsp; Any ideas how to code this?&amp;nbsp; I've started by trying to format the date_of_birth variable by coding DOB=put(date_of_birth,mmddyy8.) with no success.&amp;nbsp; Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you have any feedback ability to the source of this &lt;STRIKE&gt;garbage&lt;/STRIKE&gt; less-than-optimal-value tell them that for clarity and consistency sake that months and days of year should always be 2 digits and years should be 4 digits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date formats, such as mmddyy, only come close to working when the actual numeric value of the date is a SAS created date value which means the number underlying is the number of days from 1 Jan 1960. While you can apply the format to any random sequence of digits, like 82902, the formatted value is likely seldom going to be what you want. Also PUT function &lt;STRONG&gt;always&lt;/STRONG&gt; creates character values so would not have helped with use in any of the functions that manipulate date values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;</description>
    <pubDate>Tue, 12 Apr 2022 14:53:11 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-04-12T14:53:11Z</dc:date>
    <item>
      <title>Calculating age using birthday that is numeric format (default 8.) and date of last visit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807350#M318301</link>
      <description>&lt;P&gt;I have one variable called date_of_birth that is a numeric value with default length 8.&amp;nbsp; A couple of the values are 82902 (which is August 29, 2002) and 111797 (which is November 17, 1997).&amp;nbsp; I'll be creating a second variable, date_last_visit, in which I'll need to calculate age at time of date_last_visit.&amp;nbsp; Date_last_visit will be July 4, 2022 for everyone.&amp;nbsp; Any ideas how to code this?&amp;nbsp; I've started by trying to format the date_of_birth variable by coding DOB=put(date_of_birth,mmddyy8.) with no success.&amp;nbsp; Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 11:24:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807350#M318301</guid>
      <dc:creator>Bluekeys49</dc:creator>
      <dc:date>2022-04-12T11:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age using birthday that is numeric format (default 8.) and date of last visit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807356#M318306</link>
      <description>&lt;P&gt;In order for any of this to work, you must use valid SAS date values, which are the number of days since 01JAN1960. Most humans could not tell you how many days since 01JAN1960 until (for example), 12APR2022. Fortunately, SAS provides many tools to do the translation from 12APR2022 to a valid SAS date which is 22747, provided your "dates" are in some meaningful and recognizable form.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example: convert your "dates" into valid SAS dates, using the INPUT statement and the proper informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
     z='82902';
     zn=input(z,mmddyy.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have valid SAS dates, then computing age is done via the &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/p1pmmr2dtec32an1vbsqmm3abil5.htm" target="_self"&gt;YRDIF function&lt;/A&gt;&amp;nbsp;and using the date literal &lt;FONT face="courier new,courier"&gt;'04JUL2022'd&lt;/FONT&gt; to represent July 4, 2022.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
    z='82902';
    zn=input(z,mmddyy.);
    age=yrdif(zn,'04JUL2022'd,'age');
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Adding: if your original "dates" are numeric, then you would need to do this in order to get the input statement with the informat to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
     z=82902;
     zn=input(put(z,6.),mmddyy.);
    age=yrdif(zn,'04JUL2022'd,'age');
run;&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294090"&gt;@Bluekeys49&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I've started by trying to format the date_of_birth variable by coding DOB=put(date_of_birth,mmddyy8.) with no success.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is NOT a format issue. Format is irrelevant. The problem is that your dates must be valid SAS dates, as explained earlier.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 12:16:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807356#M318306</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-12T12:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age using birthday that is numeric format (default 8.) and date of last visit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807378#M318318</link>
      <description>&lt;P&gt;With much trial and error, my difficulty is that I'm having trouble getting that Date_of_Birth variable to be valid SAS dates.&amp;nbsp; I've coded the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;set have;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;DOB = input(Date_of_Birth,mmddyy8.);&lt;BR /&gt;run;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've also tried mmddyy. and mmddyy6. at the end of the above statement.&amp;nbsp; The new variable DOB comes back being blank for each record.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 13:04:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807378#M318318</guid>
      <dc:creator>Bluekeys49</dc:creator>
      <dc:date>2022-04-12T13:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age using birthday that is numeric format (default 8.) and date of last visit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807381#M318319</link>
      <description>&lt;P&gt;I gave an example of code where numeric date of birth 82902 is converted to a valid SAS date.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 13:23:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807381#M318319</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-12T13:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age using birthday that is numeric format (default 8.) and date of last visit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807383#M318320</link>
      <description>&lt;P&gt;See how to convert this hare-brained number to a SAS date:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dates;
input date_of_birth;
datalines;
82902
111797
;

data want;
set dates;
length string $8;
date_of_birth = input(put(date_of_birth,z6.),mmddyy6.);
format date_of_birth yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hare-brained because such a number is useless in the first place, and anybody who still uses 2-digit years after Y2K needs to have their heads examined for terminal brain-rot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this number the consequence of using PROC IMPORT? If yes, from what type of source data did you import?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 13:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807383#M318320</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-12T13:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age using birthday that is numeric format (default 8.) and date of last visit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807392#M318326</link>
      <description>&lt;P&gt;There are leading zeros for the first nine days? December 1, 2000 is 120100, right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(Removed code, that Kurt already posted)&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 13:33:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807392#M318326</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-04-12T13:33:04Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age using birthday that is numeric format (default 8.) and date of last visit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807410#M318334</link>
      <description>&lt;P&gt;Thank you very much!&amp;nbsp; It worked.&amp;nbsp; I had missed that critical&amp;nbsp;input(put(z,6.) piece which I had never used together before.&amp;nbsp; Many thanks.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 14:52:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807410#M318334</guid>
      <dc:creator>Bluekeys49</dc:creator>
      <dc:date>2022-04-12T14:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age using birthday that is numeric format (default 8.) and date of last visit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807411#M318335</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294090"&gt;@Bluekeys49&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have one variable called date_of_birth that is a numeric value with default length 8.&amp;nbsp; A couple of the values are 82902 (which is August 29, 2002) and 111797 (which is November 17, 1997).&amp;nbsp; I'll be creating a second variable, date_last_visit, in which I'll need to calculate age at time of date_last_visit.&amp;nbsp; Date_last_visit will be July 4, 2022 for everyone.&amp;nbsp; Any ideas how to code this?&amp;nbsp; I've started by trying to format the date_of_birth variable by coding DOB=put(date_of_birth,mmddyy8.) with no success.&amp;nbsp; Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you have any feedback ability to the source of this &lt;STRIKE&gt;garbage&lt;/STRIKE&gt; less-than-optimal-value tell them that for clarity and consistency sake that months and days of year should always be 2 digits and years should be 4 digits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date formats, such as mmddyy, only come close to working when the actual numeric value of the date is a SAS created date value which means the number underlying is the number of days from 1 Jan 1960. While you can apply the format to any random sequence of digits, like 82902, the formatted value is likely seldom going to be what you want. Also PUT function &lt;STRONG&gt;always&lt;/STRONG&gt; creates character values so would not have helped with use in any of the functions that manipulate date values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 14:53:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807411#M318335</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-04-12T14:53:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age using birthday that is numeric format (default 8.) and date of last visit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807412#M318336</link>
      <description>&lt;P&gt;Totally agree that these numeric input date values are not ideal at all.&amp;nbsp; Will definitely give feedback that year value should be 4 digits and not 2.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 14:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-using-birthday-that-is-numeric-format-default-8/m-p/807412#M318336</guid>
      <dc:creator>Bluekeys49</dc:creator>
      <dc:date>2022-04-12T14:57:04Z</dc:date>
    </item>
  </channel>
</rss>

