<?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: intck function will not get my desired result in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501839#M133858</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi SIr, thanks for your reply. I tried putting it into the where clause but it gave me 0 observations.&lt;/P&gt;&lt;PRE&gt;27         proc sql;
28         create table work.W40RESKE as
29                     select*
30                    from ncpdm.ncp_load_tnbt_profiling
31         /*             where newdatetime  =  intck('year',newdatetime,-2,) /*and newdatetime  &amp;lt;= today()-365*/
32         where newdatetime  &amp;gt;= intnx('month', intnx('year',newdatetime,-2,'s'),0) and newdatetime  &amp;lt;= today()
33         
34         ;
NOTE: Table WORK.W40RESKE created, with 0 rows and 31 columns.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data in the source table has records from 2014 until today and it has more than 50 mil records....&lt;/P&gt;&lt;P&gt;Do you think by any chance a small tweak to the statement will work?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Oct 2018 11:22:32 GMT</pubDate>
    <dc:creator>imdickson</dc:creator>
    <dc:date>2018-10-05T11:22:32Z</dc:date>
    <item>
      <title>intck function will not get my desired result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501812#M133849</link>
      <description>&lt;P&gt;I am trying to apply a where clause filter in a proc sql statement to only output result that is from today to 2 years earlier.&lt;/P&gt;&lt;P&gt;so today is 5th Oct 2018. I want my data to have data from 1st Oct 2016 to 5th oct 2018.&lt;/P&gt;&lt;P&gt;However, my result is always NULL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are my code:&lt;/P&gt;&lt;PRE&gt;proc sql;          
create table work.W40RESKE as
            select*
           from dm.ncp_load_tnbt_profiling
             where newdatetime  &amp;gt;=  intck('year',newdatetime,-2) and newdatetime  &amp;lt;= today()
          ;
		  quit;&lt;/PRE&gt;&lt;P&gt;May I know which part gone terribly wrong? I have read alot of intck example online and it seems like i interpreted wrongly here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 10:10:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501812#M133849</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2018-10-05T10:10:54Z</dc:date>
    </item>
    <item>
      <title>Re: intck function will not get my desired result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501815#M133851</link>
      <description>&lt;P&gt;Maxim 1: read the documentation.&lt;/P&gt;
&lt;P&gt;intck() requires three arguments: an interval designator, and two &lt;EM&gt;SAS dates&lt;/EM&gt; if a date interval is specified.&lt;/P&gt;
&lt;P&gt;-2 as a SAS date is 1959-12-30:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
format mydate yymmddd10.;
mydate = -2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You may have wanted to use the intnx() function instead, which returns a date (or datetime) from a date and an interval.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 10:19:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501815#M133851</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-05T10:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: intck function will not get my desired result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501832#M133856</link>
      <description>&lt;P&gt;You should use INTNX()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;           where newdatetime  &amp;gt;= intnx('month', intnx('year',newdatetime,-2,'s'),0) and newdatetime  &amp;lt;= today()&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Oct 2018 11:09:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501832#M133856</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-10-05T11:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: intck function will not get my desired result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501839#M133858</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi SIr, thanks for your reply. I tried putting it into the where clause but it gave me 0 observations.&lt;/P&gt;&lt;PRE&gt;27         proc sql;
28         create table work.W40RESKE as
29                     select*
30                    from ncpdm.ncp_load_tnbt_profiling
31         /*             where newdatetime  =  intck('year',newdatetime,-2,) /*and newdatetime  &amp;lt;= today()-365*/
32         where newdatetime  &amp;gt;= intnx('month', intnx('year',newdatetime,-2,'s'),0) and newdatetime  &amp;lt;= today()
33         
34         ;
NOTE: Table WORK.W40RESKE created, with 0 rows and 31 columns.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data in the source table has records from 2014 until today and it has more than 50 mil records....&lt;/P&gt;&lt;P&gt;Do you think by any chance a small tweak to the statement will work?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 11:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501839#M133858</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2018-10-05T11:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: intck function will not get my desired result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501840#M133859</link>
      <description>&lt;P&gt;Are you sure you have SAS dates in newdatetime? The code works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
newdatetime = today();
run;

proc sql;
create table work.W40RESKE as
select *
from have
where newdatetime &amp;gt;= intnx('month', intnx('year',newdatetime,-2,'s'),0) and newdatetime  &amp;lt;= today()
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;31         proc sql;
32         create table work.W40RESKE as
33         select *
34         from have
35         where newdatetime &amp;gt;= intnx('month', intnx('year',newdatetime,-2,'s'),0) and newdatetime  &amp;lt;= today()
36         ;
NOTE: Table WORK.W40RESKE created, with 1 rows and 1 columns.
&lt;/PRE&gt;
&lt;P&gt;Maxim 3: know your data.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 11:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501840#M133859</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-05T11:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: intck function will not get my desired result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501884#M133879</link>
      <description>&lt;DIV class="lia-message-body lia-component-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;My bad everyone. I forgot to tell that "newdatetime" is actually datetime format, not date.&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the thing. If i want the where clause to ignore datetime entirely without changing my original source and target column named "newdatetime" . Is there a way to do so?&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 05 Oct 2018 13:21:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501884#M133879</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2018-10-05T13:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: intck function will not get my desired result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501887#M133881</link>
      <description>&lt;P&gt;Use the datepart() function to extract dates from datetimes.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 13:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501887#M133881</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-05T13:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: intck function will not get my desired result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501909#M133897</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I applied datepart to newdatetime column in where clause. However, the where clause doesnt work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my log&lt;/P&gt;&lt;PRE&gt;27         proc sql;
28         create table work.W40RESKE as
29                     select*
30
31                    from ncpdm.ncp_load_tnbt_profiling
32         
33         where newdatetime  &amp;gt;= intnx('month', intnx('year',datepart(newdatetime),-2,'s'),0) and datepart(newdatetime)  &amp;lt;= today()
34         
35         ;
NOTE: Compressing data set WORK.W40RESKE decreased size by 53.76 percent. 
      Compressed is 313316 pages; un-compressed would require 677637 pages.
NOTE: Table WORK.W40RESKE created, with 71829414 rows and 31 columns.

36         		  quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           5:52.00
      cpu time            5:51.98&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which part do you think i did wrongly?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 14:06:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501909#M133897</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2018-10-05T14:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: intck function will not get my desired result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501911#M133898</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/63520"&gt;@imdickson&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;newdatetime &amp;gt;= intnx('month', intnx('year',datepart(newdatetime),-2,'s')&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1. you're using the same column but on the left with a SAS datetime value and on the right with a SAS data value. So that can't work.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You can use DT... directives with intnx when dealing with datetime values - so 'dtyear' instead of 'year' and then not datepart() function&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2. But besides of the above: what the heck is the logic you're trying to implement here. If you wouldn't have mixed up date with datetime then this condition would always be true as you're shifting the same column you're comparing with. That's logic like: Variable &amp;gt;= Variable -2&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 14:16:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/501911#M133898</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-10-05T14:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: intck function will not get my desired result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/502316#M134077</link>
      <description>&lt;P&gt;This&lt;/P&gt;
&lt;PRE&gt;newdatetime  &amp;gt;= intnx('month', intnx('year',datepart(newdatetime),-2,'s'),0)&lt;/PRE&gt;
&lt;P&gt;will be true for any datetime after 1960-01-01, and false for any datetime before 1959-12-31.&lt;/P&gt;
&lt;P&gt;If you used the datepart function on both parts:&lt;/P&gt;
&lt;PRE&gt;datepart(newdatetime) &amp;gt;= intnx('month', intnx('year',datepart(newdatetime),-2,'s'),0)&lt;/PRE&gt;
&lt;P&gt;it would always be true.&lt;/P&gt;
&lt;P&gt;And this&lt;/P&gt;
&lt;PRE&gt;datepart(newdatetime)  &amp;lt;= today()&lt;/PRE&gt;
&lt;P&gt;will of course be true for any datetime value that is not in the future.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Oct 2018 07:36:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intck-function-will-not-get-my-desired-result/m-p/502316#M134077</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-08T07:36:23Z</dc:date>
    </item>
  </channel>
</rss>

