<?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: subtracting dates in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/subtracting-dates/m-p/735013#M28648</link>
    <description>&lt;P&gt;I think we need to confirm what the input dataset really contains. Run this and post the results.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data = more.hcu;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 18 Apr 2021 03:54:53 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2021-04-18T03:54:53Z</dc:date>
    <item>
      <title>subtracting dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/subtracting-dates/m-p/734929#M28645</link>
      <description>&lt;P&gt;Hello, I have 2 dates and I'm trying to get the difference between them in days. One is formatted as datetime20 and the other as date9. I've tried the following and neither works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Format them both as date9 --&amp;gt; Error message, there was a problem with the format so best. was used. Not sure what best. format is or whether I needed to change the informat as well. Is the difference between 2 date9 variables come out in units of days?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want; set have;
format evrprdttm date9.;
informat evrprdttm date9.;
days=intck('dtday', evrprdttm, adate);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Reformat them both as numeric --&amp;gt; the revised dates come out as missing along with "diff"&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want; set have;
adate_revised=input(adate, mmddyy10.);
evrprdttm_revised=input(evrprdttm, mmddyy10.);
diff=evrprdttm_revised-adate_revised;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Apr 2021 21:43:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/subtracting-dates/m-p/734929#M28645</guid>
      <dc:creator>lmyers2</dc:creator>
      <dc:date>2021-04-17T21:43:23Z</dc:date>
    </item>
    <item>
      <title>Re: subtracting dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/subtracting-dates/m-p/734972#M28646</link>
      <description>&lt;P&gt;I suggest you try converting your SAS datetime to a date first then calculate the difference as days. Also if your SAS date / datetime already has formats applied there is no reason to apply them again.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want; set have;
days = intck('day', datepart(evrprdttm), adate);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Apr 2021 23:06:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/subtracting-dates/m-p/734972#M28646</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-04-17T23:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: subtracting dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/subtracting-dates/m-p/734999#M28647</link>
      <description>&lt;P&gt;Thanks SASKiwi - when I convert evrprdttm below from datetime20 to date9, I get lines and lines of the error message pasted just below it. In proc contents, the format converts successfully to date9 but in the data, the datetime July 3, 2020 6:15 ends up being in exponential form and the subtraction doesn't work.&amp;nbsp; If you have any ideas for why I keep getting this error, would greatly appreciate the help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data hcuant; set more.hcu;
format evrprdttm date9.;
days=intck('day', datepart(evrprdttm), datepart(adate));
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;ERROR: There was a problem with the format so BEST. was used.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Apr 2021 01:42:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/subtracting-dates/m-p/734999#M28647</guid>
      <dc:creator>lmyers2</dc:creator>
      <dc:date>2021-04-18T01:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: subtracting dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/subtracting-dates/m-p/735013#M28648</link>
      <description>&lt;P&gt;I think we need to confirm what the input dataset really contains. Run this and post the results.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data = more.hcu;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 18 Apr 2021 03:54:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/subtracting-dates/m-p/735013#M28648</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-04-18T03:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: subtracting dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/subtracting-dates/m-p/735029#M28649</link>
      <description>&lt;P&gt;A format only defines how a value gets printed. It does not change the actual internal value. SAS Dates and Datetime values are counts of days/counts of seconds since 1/1/1960.&lt;/P&gt;
&lt;P&gt;Any function like datepart() or intck() works on the internal values irrespective of the format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If evrprdttm really contains a SAS Datetime value and&amp;nbsp;adate a SAS Date value then below should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data hcuant; &lt;BR /&gt;  set more.hcu;
  days=intck('day', datepart(evrprdttm), adate);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;...and because SAS Date values are just counts of days since 1/1/1960 also below code will work for SAS Date values:&lt;/P&gt;
&lt;PRE&gt;data hcuant; 
  set more.hcu;
  days=adate - datepart(evrprdttm);
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Apr 2021 04:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/subtracting-dates/m-p/735029#M28649</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-18T04:32:19Z</dc:date>
    </item>
  </channel>
</rss>

