<?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 get the date difference when having 2 dates format (datetime16 and date.) in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/get-the-date-difference-when-having-2-dates-format-datetime16/m-p/637971#M21508</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to calculate the date difference between 31dec16 and the variable service_dte (which is the start date when an employee joined the company).&amp;nbsp;the format of the variable service_dte is&amp;nbsp;datetime16. and according to SAS it is in numeric value.How should I proceed? since service_dte and '31dec16' are of different format, I tried to convert the format fist, but it is not working. I am currently using SAS 9.4.&lt;/P&gt;&lt;P&gt;this is what i tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data trial;&lt;/P&gt;&lt;P&gt;set lwop.data2016;&lt;/P&gt;&lt;P&gt;service_date=input(service_dte,datetime16.);&lt;/P&gt;&lt;P&gt;format service_date date.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;i got the following error message: &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;Note: invalid argument to function input at line 3815 column. warning:limit set by errors=option reached. further errors of this type will not be printed.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;&lt;BR /&gt;&amp;nbsp;Thank you very much for your help!!&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Apr 2020 00:35:10 GMT</pubDate>
    <dc:creator>carinetang</dc:creator>
    <dc:date>2020-04-07T00:35:10Z</dc:date>
    <item>
      <title>get the date difference when having 2 dates format (datetime16 and date.)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-the-date-difference-when-having-2-dates-format-datetime16/m-p/637971#M21508</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to calculate the date difference between 31dec16 and the variable service_dte (which is the start date when an employee joined the company).&amp;nbsp;the format of the variable service_dte is&amp;nbsp;datetime16. and according to SAS it is in numeric value.How should I proceed? since service_dte and '31dec16' are of different format, I tried to convert the format fist, but it is not working. I am currently using SAS 9.4.&lt;/P&gt;&lt;P&gt;this is what i tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data trial;&lt;/P&gt;&lt;P&gt;set lwop.data2016;&lt;/P&gt;&lt;P&gt;service_date=input(service_dte,datetime16.);&lt;/P&gt;&lt;P&gt;format service_date date.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;i got the following error message: &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;Note: invalid argument to function input at line 3815 column. warning:limit set by errors=option reached. further errors of this type will not be printed.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;&lt;BR /&gt;&amp;nbsp;Thank you very much for your help!!&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2020 00:35:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-the-date-difference-when-having-2-dates-format-datetime16/m-p/637971#M21508</guid>
      <dc:creator>carinetang</dc:creator>
      <dc:date>2020-04-07T00:35:10Z</dc:date>
    </item>
    <item>
      <title>Re: get the date difference when having 2 dates format (datetime16 and date.)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-the-date-difference-when-having-2-dates-format-datetime16/m-p/637973#M21509</link>
      <description>&lt;P&gt;Formats just tell SAS how to display the values. If that variable really contains numbers that are valid datetime values (number of seconds) then to calculate the difference in DAYS you will need to convert the number of seconds into number of days.&amp;nbsp; Essentially you just need to divide by the number of seconds in a day, but there is a built in function to make it easier (and clearer).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data trial;
  set lwop.data2016;
  service_date=datepart(service_dte);
  format service_date date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have two date values (number of days) then to find a difference just subtract them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS Make sure to always display dates with 4 digits for the year to avoid confusion.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2020 01:19:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-the-date-difference-when-having-2-dates-format-datetime16/m-p/637973#M21509</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-07T01:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: get the date difference when having 2 dates format (datetime16 and date.)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-the-date-difference-when-having-2-dates-format-datetime16/m-p/637990#M21519</link>
      <description>Thank you very much for the explanation! The substraction did work!</description>
      <pubDate>Tue, 07 Apr 2020 04:59:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-the-date-difference-when-having-2-dates-format-datetime16/m-p/637990#M21519</guid>
      <dc:creator>carinetang</dc:creator>
      <dc:date>2020-04-07T04:59:26Z</dc:date>
    </item>
  </channel>
</rss>

