<?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: Calculations based on date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Calculations-based-on-date/m-p/678175#M23823</link>
    <description>&lt;P&gt;data work.report_assessment2;&lt;BR /&gt;set work.report_assessment;&lt;BR /&gt;DateTime=input(Date, anydtdtm.);&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;&amp;lt;= if this doesn't throw a warning or error then likely DATE is not a date value.&lt;/STRONG&gt;&lt;BR /&gt;format DateTime datetime20.;&lt;BR /&gt;Month1 = intck('month', Date, '20Aug2020'd, 'continuous');&lt;BR /&gt;Month2 = intck('month', DateTime, '20Aug2020'd, 'continuous');&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need compare dates to dates and datetimes to datetimes:&lt;/P&gt;
&lt;PRE&gt;data example;
   input date :date9. datetime :datetime.;
   format date date9. datetime datetime18.;
   datedif = intck('month',date,today(),'c');
   /*wrong as the following comparing a date with DT 
     uses different units*/
   todayasdatetime = today();&lt;BR /&gt;   /* format date as datetime to show how the value will be used&lt;BR /&gt;      intck function with DT intervals&lt;BR /&gt;   */
   format todayasdatetime datetime18.;
   dtdif1   = intck('dtmonth',datetime,todayasdatetime,'c');
   /* compare datetime to datetime*/
   dtdif2   = intck('dtmonth',datetime, dhms(today(),0,0,time()),'c');

datalines;
21Jun2020   23Mar2020:12:15:13
;
   &lt;/PRE&gt;</description>
    <pubDate>Thu, 20 Aug 2020 16:47:49 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-08-20T16:47:49Z</dc:date>
    <item>
      <title>Calculations based on date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculations-based-on-date/m-p/678146#M23819</link>
      <description>&lt;P&gt;Hello!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to calculate the difference between a date variable and today's date, using the INTCK function. I am trying to see if there is a difference between calculations using date variables or datetime variables. Here is my code:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data work.report_assessment2;&lt;BR /&gt;set work.report_assessment;&lt;BR /&gt;DateTime=input(Date, anydtdtm.);&lt;BR /&gt;format DateTime datetime20.;&lt;BR /&gt;Month1 = intck('month', Date, '20Aug2020'd, 'continuous');&lt;BR /&gt;Month2 = intck('month', DateTime, '20Aug2020'd, 'continuous');&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this the correct code? Month1 and Month2 end up as blank variables.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Aug 2020 15:42:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculations-based-on-date/m-p/678146#M23819</guid>
      <dc:creator>marleeakerson</dc:creator>
      <dc:date>2020-08-20T15:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations based on date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculations-based-on-date/m-p/678152#M23820</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281255"&gt;@marleeakerson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to calculate the difference between a date variable and today's date, using the INTCK function. I am trying to see if there is a difference between calculations using date variables or datetime variables. Here is my code:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data work.report_assessment2;&lt;BR /&gt;set work.report_assessment;&lt;BR /&gt;DateTime=input(Date, anydtdtm.);&lt;BR /&gt;format DateTime datetime20.;&lt;BR /&gt;Month1 = intck('month', Date, '20Aug2020'd, 'continuous');&lt;BR /&gt;Month2 = intck('month', DateTime, '20Aug2020'd, 'continuous');&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this the correct code? Month1 and Month2 end up as blank variables.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Did you look at this data set? Does DATE have a value? Is it numeric or character? What is a typical value of DATE?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, when you straighten that out, you need to fix this part as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Month2 = intck('dtmonth', DateTime, '20Aug2020'd, 'continuous');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Depending on your answers to my questions above, there may be other errors that need to be fixed as well.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Aug 2020 16:35:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculations-based-on-date/m-p/678152#M23820</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-20T16:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations based on date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculations-based-on-date/m-p/678175#M23823</link>
      <description>&lt;P&gt;data work.report_assessment2;&lt;BR /&gt;set work.report_assessment;&lt;BR /&gt;DateTime=input(Date, anydtdtm.);&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;&amp;lt;= if this doesn't throw a warning or error then likely DATE is not a date value.&lt;/STRONG&gt;&lt;BR /&gt;format DateTime datetime20.;&lt;BR /&gt;Month1 = intck('month', Date, '20Aug2020'd, 'continuous');&lt;BR /&gt;Month2 = intck('month', DateTime, '20Aug2020'd, 'continuous');&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need compare dates to dates and datetimes to datetimes:&lt;/P&gt;
&lt;PRE&gt;data example;
   input date :date9. datetime :datetime.;
   format date date9. datetime datetime18.;
   datedif = intck('month',date,today(),'c');
   /*wrong as the following comparing a date with DT 
     uses different units*/
   todayasdatetime = today();&lt;BR /&gt;   /* format date as datetime to show how the value will be used&lt;BR /&gt;      intck function with DT intervals&lt;BR /&gt;   */
   format todayasdatetime datetime18.;
   dtdif1   = intck('dtmonth',datetime,todayasdatetime,'c');
   /* compare datetime to datetime*/
   dtdif2   = intck('dtmonth',datetime, dhms(today(),0,0,time()),'c');

datalines;
21Jun2020   23Mar2020:12:15:13
;
   &lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Aug 2020 16:47:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculations-based-on-date/m-p/678175#M23823</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-20T16:47:49Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations based on date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculations-based-on-date/m-p/678178#M23824</link>
      <description>&lt;P&gt;The code is definitely wrong. Without knowing what you have it is hard to know exactly which parts are wrong.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The variable DATE can either be a character string. In which case this line could work (depending on what values it has).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DateTime=input(Date, anydtdtm.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or it is a numeric variable in which case this line could work, as long as the number is the number of days and not the number of seconds that the statement above is trying to assign to the other variable DATETIME.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Month1 = intck('month', Date, '20Aug2020'd, 'continuous'); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If DATE is a string and you want to convert it to a date value use the ANYDTDTE informat instead of the ANYDTDTM informat.&amp;nbsp; If DATE is a number with a date value (number of days) and you want to create a datetime value then use the DHMS() function and supply the time of day you want to use, usually midnight is used.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DateTime = dhms(date,0,0,0); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If DATE is a number with a datetime value (number of seconds) and you want to count months you can either use the DTMONTH interval&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Month1 = intck('dtmonth', Date, '20Aug2020:00:00:00'dt, 'continuous'); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or convert it to a date value and use the MONTH interval.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Month1 = intck('month', datepart(Date), '20Aug2020'd, 'continuous'); &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Aug 2020 17:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculations-based-on-date/m-p/678178#M23824</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-20T17:03:12Z</dc:date>
    </item>
  </channel>
</rss>

