<?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: how to calculate or compare the interval in no. of days between 2 date field column in SAS PROC in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-or-compare-the-interval-in-no-of-days-between-2/m-p/755707#M238525</link>
    <description>&lt;P class="xis-shortDescription"&gt;If you want to compare dates then why are you using "trunc"? That function is designed to truncate a numeric value to a specified number of bytes. Which expects a "number of bytes" as an argument and most of your "dates" would no longer represent the same date if truncated.&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;If the value returned from Oracle is actually a datetime value then you want to use either the function DATEPART(variable) to get just the date portion of a value that includes time, or use the INTCK function such as&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;if intck('dtday',b.CFR_CREATE_DATE,b.BAN_START_DATE)=0 then "Primary"&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;The Intck function returns number of intervals between two date, datetime or time values. The first parameter is the type of interval. If the values are datetime you use DTday, DTmonth, DTweek, DTyear to find the number of intervals based on day, month, week or year. If the values were simple dates then intervals are like day, week, month, year.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Jul 2021 17:09:33 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-07-21T17:09:33Z</dc:date>
    <item>
      <title>how to calculate or compare the interval in no. of days between 2 date field column in SAS PROC SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-or-compare-the-interval-in-no-of-days-between-2/m-p/755705#M238524</link>
      <description>&lt;P&gt;Executed the below SAS script with case statement to populate the value of subscriber_type as 'Primary' if&amp;nbsp; the date fields CFR_CREATE_DATE = BAN_START_DATE&amp;nbsp;&lt;/P&gt;&lt;P&gt;and if the difference between&amp;nbsp;CFR_CREATE_DATE minus BAN_START_DATE &amp;lt;= 30 days then the value of&amp;nbsp;subscriber_type will be&amp;nbsp;'AAL &amp;lt;= 30'&lt;/P&gt;&lt;P&gt;and if the&amp;nbsp;difference between&amp;nbsp;CFR_CREATE_DATE minus BAN_START_DATE &amp;gt; 30&lt;/P&gt;&lt;P&gt;then&amp;nbsp;'AAL &amp;gt; 30' else Null. How can this be done in PROC SQL?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: CFR_CREATE_DATE &amp;amp; BAN_START_DATE used in the below script are both date data type fields&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;SAS SCRIPT:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;connect to oracle(&amp;amp;xyz);&lt;BR /&gt;create table CANCELS_SUB as&lt;BR /&gt;Select&amp;nbsp;&lt;BR /&gt;CASE&lt;BR /&gt;WHEN TRUNC(b.CFR_CREATE_DATE) = TRUNC(b.BAN_START_DATE) THEN 'PRIMARY'&lt;BR /&gt;WHEN TRUNC(b.CFR_CREATE_DATE) &amp;lt;&amp;gt; TRUNC(b.BAN_START_DATE)&lt;BR /&gt;AND (TRUNC(b.CFR_CREATE_DATE) - TRUNC(b.BAN_START_DATE)) &amp;lt;= 30 THEN 'AAL &amp;lt;= 30'&lt;BR /&gt;WHEN TRUNC(b.CFR_CREATE_DATE) &amp;lt;&amp;gt; TRUNC(b.BAN_START_DATE)&lt;BR /&gt;AND (TRUNC(b.CFR_CREATE_DATE) - TRUNC(b.BAN_START_DATE)) &amp;gt; 30 THEN 'AAL &amp;gt; 30'&lt;BR /&gt;ELSE NULL&lt;BR /&gt;END as SUBSCRIBER_TYPE&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;from WORK.'COPY OF TRANSACTIONAL SURVEY DAT'n a&lt;BR /&gt;left join xys.DAILY_CONSUMER_POST_CANCELS b&lt;BR /&gt;ON a.BAN = b.BAN ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Error Log:&lt;/U&gt;&lt;BR /&gt;NOTE: The "&amp;lt;&amp;gt;" operator is interpreted as "not equals".&lt;BR /&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Expression using subtraction (-) requires numeric types.&lt;BR /&gt;2 The SAS System 11:31 Wednesday, July 21, 2021&lt;/P&gt;&lt;P&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Expression using subtraction (-) requires numeric types.&lt;BR /&gt;ERROR: The following columns were not found in the contributing tables: NULL.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jul 2021 16:59:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-or-compare-the-interval-in-no-of-days-between-2/m-p/755705#M238524</guid>
      <dc:creator>vini5</dc:creator>
      <dc:date>2021-07-21T16:59:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate or compare the interval in no. of days between 2 date field column in SAS PROC</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-or-compare-the-interval-in-no-of-days-between-2/m-p/755707#M238525</link>
      <description>&lt;P class="xis-shortDescription"&gt;If you want to compare dates then why are you using "trunc"? That function is designed to truncate a numeric value to a specified number of bytes. Which expects a "number of bytes" as an argument and most of your "dates" would no longer represent the same date if truncated.&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;If the value returned from Oracle is actually a datetime value then you want to use either the function DATEPART(variable) to get just the date portion of a value that includes time, or use the INTCK function such as&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;if intck('dtday',b.CFR_CREATE_DATE,b.BAN_START_DATE)=0 then "Primary"&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;The Intck function returns number of intervals between two date, datetime or time values. The first parameter is the type of interval. If the values are datetime you use DTday, DTmonth, DTweek, DTyear to find the number of intervals based on day, month, week or year. If the values were simple dates then intervals are like day, week, month, year.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jul 2021 17:09:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-or-compare-the-interval-in-no-of-days-between-2/m-p/755707#M238525</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-21T17:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate or compare the interval in no. of days between 2 date field column in SAS PROC</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-or-compare-the-interval-in-no-of-days-between-2/m-p/755708#M238526</link>
      <description>&lt;PRE&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;/PRE&gt;
&lt;P&gt;It requires two arguments, and your calls to TRUNC have only 1 argument. So what are the two arguments? Let's read the documentation at&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/n1lfp83m4yht68n1luxn5tnmuhp3.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/n1lfp83m4yht68n1luxn5tnmuhp3.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Honestly, I don't think TRUNC is what you want here, but its not clear to me what other function is appropriate here. Can you state, in words, what you want TRUNC (or a replacement function) to do?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jul 2021 17:09:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-or-compare-the-interval-in-no-of-days-between-2/m-p/755708#M238526</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-07-21T17:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate or compare the interval in no. of days between 2 date field column in SAS PROC</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-or-compare-the-interval-in-no-of-days-between-2/m-p/755732#M238536</link>
      <description>&lt;P&gt;Looks like you're trying to use Pass Through SQL incorrectly so it's using the SAS TRUNC function when you want to use the ORACLE version.&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;&lt;U&gt;SAS SCRIPT:&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;connect to oracle(&amp;amp;xyz);&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But you're also using a WORK table and a SQL table, which cannot occur in Pass through.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;from WORK.'COPY OF TRANSACTIONAL SURVEY DAT'n a&lt;BR /&gt;left join xys.DAILY_CONSUMER_POST_CANCELS b&lt;BR /&gt;ON a.BAN = b.BAN ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So you need to not use SQL pass through for sure, ensure you're using SAS functions - so likely DATEPART and not TRUNC.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First figure out the libname/connection statement and then the query below should be pretty close to what you need. Its common for DB to store dates as datetimes, so I think you do need the datepart function here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname odbc myDB dsn=myData pwd= user= schema=dbo;

proc sql;
create table CANCELS_SUB as
Select 
CASE
WHEN datepart(b.CFR_CREATE_DATE) = datepart(b.BAN_START_DATE) THEN 'PRIMARY'
WHEN datepart(b.CFR_CREATE_DATE) ne datepart(b.BAN_START_DATE)
AND (datepart(b.CFR_CREATE_DATE) - datepart(b.BAN_START_DATE)) &amp;lt;= 30 THEN 'AAL &amp;lt;= 30'
WHEN datepart(b.CFR_CREATE_DATE) ne datepart(b.BAN_START_DATE)
AND (datepart(b.CFR_CREATE_DATE) - datepart(b.BAN_START_DATE)) &amp;gt; 30 THEN 'AAL &amp;gt; 30'
ELSE ''
END as SUBSCRIBER_TYPE


from WORK.'COPY OF TRANSACTIONAL SURVEY DAT'n a
left join xys.DAILY_CONSUMER_POST_CANCELS b
ON a.BAN = b.BAN ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/380426"&gt;@vini5&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Executed the below SAS script with case statement to populate the value of subscriber_type as 'Primary' if&amp;nbsp; the date fields CFR_CREATE_DATE = BAN_START_DATE&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and if the difference between&amp;nbsp;CFR_CREATE_DATE minus BAN_START_DATE &amp;lt;= 30 days then the value of&amp;nbsp;subscriber_type will be&amp;nbsp;'AAL &amp;lt;= 30'&lt;/P&gt;
&lt;P&gt;and if the&amp;nbsp;difference between&amp;nbsp;CFR_CREATE_DATE minus BAN_START_DATE &amp;gt; 30&lt;/P&gt;
&lt;P&gt;then&amp;nbsp;'AAL &amp;gt; 30' else Null. How can this be done in PROC SQL?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: CFR_CREATE_DATE &amp;amp; BAN_START_DATE used in the below script are both date data type fields&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;SAS SCRIPT:&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;connect to oracle(&amp;amp;xyz);&lt;BR /&gt;create table CANCELS_SUB as&lt;BR /&gt;Select&amp;nbsp;&lt;BR /&gt;CASE&lt;BR /&gt;WHEN TRUNC(b.CFR_CREATE_DATE) = TRUNC(b.BAN_START_DATE) THEN 'PRIMARY'&lt;BR /&gt;WHEN TRUNC(b.CFR_CREATE_DATE) &amp;lt;&amp;gt; TRUNC(b.BAN_START_DATE)&lt;BR /&gt;AND (TRUNC(b.CFR_CREATE_DATE) - TRUNC(b.BAN_START_DATE)) &amp;lt;= 30 THEN 'AAL &amp;lt;= 30'&lt;BR /&gt;WHEN TRUNC(b.CFR_CREATE_DATE) &amp;lt;&amp;gt; TRUNC(b.BAN_START_DATE)&lt;BR /&gt;AND (TRUNC(b.CFR_CREATE_DATE) - TRUNC(b.BAN_START_DATE)) &amp;gt; 30 THEN 'AAL &amp;gt; 30'&lt;BR /&gt;ELSE NULL&lt;BR /&gt;END as SUBSCRIBER_TYPE&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;from WORK.'COPY OF TRANSACTIONAL SURVEY DAT'n a&lt;BR /&gt;left join xys.DAILY_CONSUMER_POST_CANCELS b&lt;BR /&gt;ON a.BAN = b.BAN ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Error Log:&lt;/U&gt;&lt;BR /&gt;NOTE: The "&amp;lt;&amp;gt;" operator is interpreted as "not equals".&lt;BR /&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Expression using subtraction (-) requires numeric types.&lt;BR /&gt;2 The SAS System 11:31 Wednesday, July 21, 2021&lt;/P&gt;
&lt;P&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Function TRUNC requires at least 2 argument(s).&lt;BR /&gt;ERROR: Expression using subtraction (-) requires numeric types.&lt;BR /&gt;ERROR: The following columns were not found in the contributing tables: NULL.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jul 2021 19:35:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-or-compare-the-interval-in-no-of-days-between-2/m-p/755732#M238536</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-07-21T19:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate or compare the interval in no. of days between 2 date field column in SAS PROC</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-or-compare-the-interval-in-no-of-days-between-2/m-p/755751#M238543</link>
      <description>&lt;P&gt;I'm using TRUNC to perform the function of removing the timestamp from the date field to retain only the date portion.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jul 2021 21:04:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-or-compare-the-interval-in-no-of-days-between-2/m-p/755751#M238543</guid>
      <dc:creator>vini5</dc:creator>
      <dc:date>2021-07-21T21:04:49Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate or compare the interval in no. of days between 2 date field column in SAS PROC</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-or-compare-the-interval-in-no-of-days-between-2/m-p/755761#M238549</link>
      <description>That is the Oracle definition of the TRUNC function but that's not what the TRUNC function does in SAS SQL so you need to clarify my point regarding pass through versus non pass through. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;SAS: &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/n1lfp83m4yht68n1luxn5tnmuhp3.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/n1lfp83m4yht68n1luxn5tnmuhp3.htm&lt;/A&gt;&lt;BR /&gt;TRUNC Function&lt;BR /&gt;Truncates a numeric value to a specified number of bytes.&lt;BR /&gt;&lt;BR /&gt;Oracle: &lt;A href="https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions201.htm" target="_blank"&gt;https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions201.htm&lt;/A&gt;&lt;BR /&gt;The TRUNC (date) function returns date with the time portion of the day truncated to the unit specified by the format model fmt. The value returned is always of datatype DATE, even if you specify a different datetime datatype for date. If you omit fmt, then date is truncated to the nearest day. Please refer to "ROUND and TRUNC Date Functions" for the permitted format models to use in fmt.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Jul 2021 21:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-or-compare-the-interval-in-no-of-days-between-2/m-p/755761#M238549</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-07-21T21:45:34Z</dc:date>
    </item>
  </channel>
</rss>

