<?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: Creating an Age Variable from a DOB Numeric Value in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819377#M34730</link>
    <description>&lt;P&gt;Some approaches are outlined in the links here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2011/07/12/computing-age-in-sas-9-3/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2011/07/12/computing-age-in-sas-9-3/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2017/05/15/intck-intnx-intervals-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2017/05/15/intck-intnx-intervals-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://kb.iu.edu/d/aczw#:~:text=To%20compute%20age%20using%20a,122275%2002%20010865%2003%20030586%20.%20" target="_blank"&gt;https://kb.iu.edu/d/aczw#:~:text=To%20compute%20age%20using%20a,122275%2002%20010865%2003%20030586%20.%20&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Jun 2022 16:38:50 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-06-21T16:38:50Z</dc:date>
    <item>
      <title>Creating an Age Variable from a DOB Numeric Value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819357#M34727</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;I have a numeric DOB variable that I would like to use to generate an Age variable. I am not sure how to get started. I would like to use the new age variable to generate descriptive statistics on age etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what my data looks like:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;DOB&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;04/13/1950&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;09/12/1965&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;03/12/1960&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;05/17/1952&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I would like to create:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Age (years)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;72.2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what my code looks like: The DOB variable is already in numeric format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;PROC IMPORT OUT = DEMO
	DATAFILE= "M:\SAS\BI EYE-DMI\XLS Data Files/DM.xlsx"
	DBMS = xlsx;
RUN;

/* create overall variable */
DATA DEMO2;
	SET DEMO; 
	OVERALL = "Overall"; 
RUN;

TITLE "Subject AGE Overall - converting date of birth to age"; 
PROC MEANS DATA=WORK.DEMO2 MEAN STDDEV MIN MAX KURT SKEW;
	CLASS OVERALL;
	VAR DOB;
RUN;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;T.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2022 15:49:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819357#M34727</guid>
      <dc:creator>SAS_Novice22</dc:creator>
      <dc:date>2022-06-21T15:49:17Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an Age Variable from a DOB Numeric Value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819377#M34730</link>
      <description>&lt;P&gt;Some approaches are outlined in the links here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2011/07/12/computing-age-in-sas-9-3/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2011/07/12/computing-age-in-sas-9-3/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2017/05/15/intck-intnx-intervals-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2017/05/15/intck-intnx-intervals-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://kb.iu.edu/d/aczw#:~:text=To%20compute%20age%20using%20a,122275%2002%20010865%2003%20030586%20.%20" target="_blank"&gt;https://kb.iu.edu/d/aczw#:~:text=To%20compute%20age%20using%20a,122275%2002%20010865%2003%20030586%20.%20&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2022 16:38:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819377#M34730</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-21T16:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an Age Variable from a DOB Numeric Value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819378#M34731</link>
      <description>&lt;P&gt;Age as of today? Age as of some other date?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2022 16:42:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819378#M34731</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-21T16:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an Age Variable from a DOB Numeric Value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819463#M34732</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; To chime in with a contribution once you provide some more context for what you want as the age (as of today, as of Jan 1, etc), you also need to test the various ways you can calculate age. I am a fan for simple age of subtraction, plus division, as shown in the program below for the AGE_TODAY variable, which uses the today() function to get today's date and then subtracts the internal value for DOB. Then the resulting number of days is how many days old -- which still needs to have a calculation done to get fractional years old for the age. I use 365.25 as the denominator, to account for leap year every 4 years and the age that comes out is fairly close. The INTCK function provides an alternate way to provide interval checking between 2 dates. But if you pick years as the interval, then it will count whole years. So depending on what you want/need, you can get different values for age:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_1-1655843954809.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72515i88958523F9AA082B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_1-1655843954809.png" alt="Cynthia_sas_1-1655843954809.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2022 20:39:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819463#M34732</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2022-06-21T20:39:31Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an Age Variable from a DOB Numeric Value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819468#M34733</link>
      <description>Hi Cyntia,&lt;BR /&gt;This is exactly what I was looking for, thank you for the code and the excellent information. Thanks for providing the solution to my question.&lt;BR /&gt;Best wishes,&lt;BR /&gt;T.</description>
      <pubDate>Tue, 21 Jun 2022 21:06:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819468#M34733</guid>
      <dc:creator>SAS_Novice22</dc:creator>
      <dc:date>2022-06-21T21:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an Age Variable from a DOB Numeric Value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819664#M34763</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi Cyntia,&lt;/P&gt;&lt;P&gt;I tried out the code and here is what I am getting. What I am not sure about is what I should put in the infile section since I have more than 266 subject datalines that I would like to have DOB converted for. I would like to see all options as well (today, Jan 1, and intck).&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what my SAS code looks like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;DATA WORK.DEMO2;
	SET DEMO;
	INPUT NAME $ DOB : MMDDYY.;
	AGE_TODAY = ((today()-DOB)/365.25);
	AGE_JAN1 = (('01JAN2022'D - DOB)/365.25);
	AGE_INTCK = INTCK('YEAR', DOB, TODAY(), 'CONTINUOUS');
RETURN;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here is what my log looks like:&lt;/P&gt;&lt;PRE&gt;121  DATA WORK.DEMO2;
122      SET DEMO;
123      INPUT NAME $ DOB : MMDDYY.;
124      AGE_TODAY = ((today()-DOB)/365.25);
125      AGE_JAN1 = (('01JAN2022'D - DOB)/365.25);
126      AGE_INTCK = INTCK('YEAR', DOB, TODAY(), 'CONTINUOUS');
127  RETURN;
128  RUN;

ERROR: No DATALINES or INFILE statement.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.DEMO2 may be incomplete.  When this step was stopped there were 0
         observations and 39 variables.
WARNING: Data set WORK.DEMO2 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds&lt;/PRE&gt;&lt;P&gt;Any further assistance you could provide would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best wishes,&lt;/P&gt;&lt;P&gt;T.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2022 15:26:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819664#M34763</guid>
      <dc:creator>SAS_Novice22</dc:creator>
      <dc:date>2022-06-22T15:26:33Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an Age Variable from a DOB Numeric Value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819668#M34764</link>
      <description>&lt;P&gt;SET is for reading from SAS datasets.&lt;/P&gt;
&lt;P&gt;INPUT is for reading from text files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So which do you have?&amp;nbsp; You will not normally use both in the same data step.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2022 15:35:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819668#M34764</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-22T15:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an Age Variable from a DOB Numeric Value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819671#M34765</link>
      <description>That was what I was doing wrong. Thank you!! It worked like a charm.</description>
      <pubDate>Wed, 22 Jun 2022 15:39:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819671#M34765</guid>
      <dc:creator>SAS_Novice22</dc:creator>
      <dc:date>2022-06-22T15:39:51Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an Age Variable from a DOB Numeric Value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819673#M34766</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;&amp;nbsp;- thank you both for your help. The revised code worked exactly how I was hoping.&lt;/P&gt;&lt;PRE&gt;DATA WORK.DEMO2;
	SET DEMO;
	AGE_TODAY = ((today()- DOB)/365.25);
	AGE_JAN1 = (('01JAN2022'D - DOB)/365.25);
	AGE_INTCK = INTCK('YEAR', DOB, TODAY(), 'CONTINUOUS');
RUN;&lt;/PRE&gt;&lt;P&gt;Thank you Thank you.&lt;/P&gt;&lt;P&gt;T.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2022 15:40:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819673#M34766</guid>
      <dc:creator>SAS_Novice22</dc:creator>
      <dc:date>2022-06-22T15:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an Age Variable from a DOB Numeric Value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819715#M34768</link>
      <description>Hi: As &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; pointed out, you did not need the INFILE statement. Since you did not provide test data in the form of a program that someone could run, I made some FAKE data using the INFILE and INPUT statements -- using DATALINES as a section to provide the "raw" data. The relevant statements were the 3 assignment statements, which you would need to put into your program and adjust the new variable names as you need.&lt;BR /&gt;Cynthia&lt;BR /&gt;(and thanks, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; for jumping in with the solution)</description>
      <pubDate>Wed, 22 Jun 2022 16:44:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-an-Age-Variable-from-a-DOB-Numeric-Value/m-p/819715#M34768</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2022-06-22T16:44:16Z</dc:date>
    </item>
  </channel>
</rss>

