<?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 between a Date and a Datetime format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-between-a-Date-and-a-Datetime-format/m-p/343842#M78965</link>
    <description>&lt;P&gt;Try:&lt;/P&gt;
&lt;PRE&gt;data demog;
    set '/folders/myfolders/Protocols/ATC9701/SAS Data/demog.sas7bdat';
    age = INT(YRDIF(datepart(DOB),today(),'ACTUAL'));    
run;&lt;/PRE&gt;
&lt;P&gt;DATEPART is the function to extract the date from a datetime variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You really should have a library assigned to folders/myfolders/Protocols/ATC9701/SAS Data/&lt;/P&gt;
&lt;P&gt;such as&lt;/P&gt;
&lt;P&gt;LIbname proj '/folders/myfolders/Protocols/ATC9701/SAS Data';&lt;/P&gt;
&lt;P&gt;and then use the library.set notation to refer to data sets.&lt;/P&gt;
&lt;P&gt;The change woudl look like:&lt;/P&gt;
&lt;PRE&gt;data demog;
    set proj.demog;
    age = INT(YRDIF(datepart(DOB),today(),'ACTUAL'));    
run;&lt;/PRE&gt;
&lt;P&gt;which would write the results into your Work library.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or&lt;/P&gt;
&lt;PRE&gt;data proj.demog2;
    set proj.demog;
    age = INT(YRDIF(datepart(DOB),today(),'ACTUAL'));    
run;&lt;/PRE&gt;
&lt;P&gt;to write the modified set into the same storage location.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Libraries are a key part of SAS syntax and extremely useful for keeping related data together.&lt;/P&gt;</description>
    <pubDate>Thu, 23 Mar 2017 19:59:24 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-03-23T19:59:24Z</dc:date>
    <item>
      <title>Calculating age between a Date and a Datetime format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-between-a-Date-and-a-Datetime-format/m-p/343836#M78962</link>
      <description>&lt;P&gt;It's been over 10 years since I used SAS, so I'm very rusty and was hoping to see if there was a better way of doing this.&amp;nbsp; I have a database that stores the Date of Birth (DOB) in a datetime informat, and I want to calculate the age using the today() date funciton.&amp;nbsp; Both dates are stored differently internally (date vs datetime) and thus must be converted to a common denominator before any calculation can be done.&amp;nbsp; Below is my program, and it works, but is there a better way of doing this?&amp;nbsp; Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;data demog;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;set '/folders/myfolders/Protocols/ATC9701/SAS Data/demog.sas7bdat';&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;DOBTemp=put(DOB, datetime7.);&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;DOBFinal = input(DOBTemp, date.);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;age = INT(YRDIF(DOBFinal,today(),'ACTUAL'));&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 19:51:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-between-a-Date-and-a-Datetime-format/m-p/343836#M78962</guid>
      <dc:creator>Rudy</dc:creator>
      <dc:date>2017-03-23T19:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age between a Date and a Datetime format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-between-a-Date-and-a-Datetime-format/m-p/343842#M78965</link>
      <description>&lt;P&gt;Try:&lt;/P&gt;
&lt;PRE&gt;data demog;
    set '/folders/myfolders/Protocols/ATC9701/SAS Data/demog.sas7bdat';
    age = INT(YRDIF(datepart(DOB),today(),'ACTUAL'));    
run;&lt;/PRE&gt;
&lt;P&gt;DATEPART is the function to extract the date from a datetime variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You really should have a library assigned to folders/myfolders/Protocols/ATC9701/SAS Data/&lt;/P&gt;
&lt;P&gt;such as&lt;/P&gt;
&lt;P&gt;LIbname proj '/folders/myfolders/Protocols/ATC9701/SAS Data';&lt;/P&gt;
&lt;P&gt;and then use the library.set notation to refer to data sets.&lt;/P&gt;
&lt;P&gt;The change woudl look like:&lt;/P&gt;
&lt;PRE&gt;data demog;
    set proj.demog;
    age = INT(YRDIF(datepart(DOB),today(),'ACTUAL'));    
run;&lt;/PRE&gt;
&lt;P&gt;which would write the results into your Work library.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or&lt;/P&gt;
&lt;PRE&gt;data proj.demog2;
    set proj.demog;
    age = INT(YRDIF(datepart(DOB),today(),'ACTUAL'));    
run;&lt;/PRE&gt;
&lt;P&gt;to write the modified set into the same storage location.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Libraries are a key part of SAS syntax and extremely useful for keeping related data together.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 19:59:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-between-a-Date-and-a-Datetime-format/m-p/343842#M78965</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-23T19:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age between a Date and a Datetime format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-between-a-Date-and-a-Datetime-format/m-p/343849#M78968</link>
      <description>I completely forgot about DATEPART! Thank you, and yes, thank you for reminding me about using my libraries. I wrote a quick LIBNAME program to set my library location, I didn't even use them. Thanks for the quick and accurate reply!</description>
      <pubDate>Thu, 23 Mar 2017 20:08:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-between-a-Date-and-a-Datetime-format/m-p/343849#M78968</guid>
      <dc:creator>Rudy</dc:creator>
      <dc:date>2017-03-23T20:08:08Z</dc:date>
    </item>
  </channel>
</rss>

