<?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: adding weeks to the max of the date and comparing it with datetimefield in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/adding-weeks-to-the-max-of-the-date-and-comparing-it-with/m-p/737893#M230090</link>
    <description>Thanks for the explanation. It helped me for testing.</description>
    <pubDate>Thu, 29 Apr 2021 13:14:26 GMT</pubDate>
    <dc:creator>SASAna</dc:creator>
    <dc:date>2021-04-29T13:14:26Z</dc:date>
    <item>
      <title>adding weeks to the max of the date and comparing it with datetimefield</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-weeks-to-the-max-of-the-date-and-comparing-it-with/m-p/737765#M230032</link>
      <description>&lt;P&gt;Hi SAS Users,&lt;/P&gt;
&lt;P&gt;Need a help solving the dates correctly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for the members where the datetime1 is 2 weeks greater than max_datetime2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;b.datetime1 -&amp;nbsp; Ex: 06FEB2021:11:37:16.453000&amp;nbsp; &amp;nbsp;( it is in date time format)&lt;/P&gt;
&lt;P&gt;a.a.max_datetime2 - it is max of some datetime field . ( It is in numeric format)&amp;nbsp; - Ex:&amp;nbsp;1925365763.1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My Query -&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table two_weeks as&amp;nbsp;&lt;BR /&gt;select a.memberid,&amp;nbsp;a.callid,count(*)&lt;BR /&gt;from &lt;BR /&gt;table1 a inner join table2 b &lt;BR /&gt;on a.memberid = b.memberid&lt;BR /&gt;and b.datetime1 &amp;gt;= (a.max_datetime2 + 2 weeks )&lt;BR /&gt;group by a.memberid, a.callid&lt;BR /&gt;;&lt;BR /&gt;Quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Ana&lt;/P&gt;</description>
      <pubDate>Wed, 28 Apr 2021 23:37:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-weeks-to-the-max-of-the-date-and-comparing-it-with/m-p/737765#M230032</guid>
      <dc:creator>SASAna</dc:creator>
      <dc:date>2021-04-28T23:37:06Z</dc:date>
    </item>
    <item>
      <title>Re: adding weeks to the max of the date and comparing it with datetimefield</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-weeks-to-the-max-of-the-date-and-comparing-it-with/m-p/737781#M230040</link>
      <description>&lt;P&gt;You might want to provide a variety of actual values to compare. Since you have datetime values you need to consider how the TIME component affects your comparison.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider if I have a datetime that is noon (12:00:00 time component). If I compare to datatime the next day is it "one day" if the time is only 11:30:00? For some purposes it may, for others it may not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can get the intervals between two dates, times or datetimes by using the INTCK function. The function takes as the first parameter a description of the interval of interest. For datetime values the common intervals would be 'dtday' 'dtweek' 'dtmonth' 'dtyear' 'hour' 'minute' 'second'. Some examples with the 'dtweek'&lt;/P&gt;
&lt;PRE&gt;data example;
   dt1 = '06FEB2021:11:37:16'dt;
   dt2 = '13Feb2021:10:00:00'dt;
   dt3 = '13Feb2021:12:00:00'dt;
   /* continuous considers the time interval differently
      since the second time is not the same or later than
      the first it is not a complete week
   */
   dt1_dt2_c = intck('dtweek',dt1, dt2,'continuous');
   dt1_dt2_d = intck('dtweek',dt1, dt2,'discrete');
   dt1_dt3_c = intck('dtweek',dt1, dt3,'c');
   dt1_dt3_d = intck('dtweek',dt1, dt3,'d');
   /* discrete is the default for the last parameter if not provided*/
run;

&lt;/PRE&gt;
&lt;P&gt;The DT tells SAS the values are expected to be datetimes and not dates which use 'week' 'month' 'day' 'year'.&lt;/P&gt;
&lt;P&gt;So you use the function to return the number of intervals directly such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and intck('dtweek',a.max_datetime2, b.datetime1,'d') ge 2&amp;nbsp;&lt;/P&gt;
&lt;P&gt;( if I parsed your code correctly)&lt;/P&gt;
&lt;P&gt;for example. Use the appropriate 'd' or 'c' for YOUR purpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is another function INTNX to increment dates, times and datetime values&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 01:07:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-weeks-to-the-max-of-the-date-and-comparing-it-with/m-p/737781#M230040</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-29T01:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: adding weeks to the max of the date and comparing it with datetimefield</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-weeks-to-the-max-of-the-date-and-comparing-it-with/m-p/737792#M230041</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;b.datetime1 &amp;gt;= intnx('dtday', a.max_datetime2, 14, 's' )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Try INTNX and DTDAY as the interval, which is 14 days.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/86567"&gt;@SASAna&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi SAS Users,&lt;/P&gt;
&lt;P&gt;Need a help solving the dates correctly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for the members where the datetime1 is 2 weeks greater than max_datetime2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;b.datetime1 -&amp;nbsp; Ex: 06FEB2021:11:37:16.453000&amp;nbsp; &amp;nbsp;( it is in date time format)&lt;/P&gt;
&lt;P&gt;a.a.max_datetime2 - it is max of some datetime field . ( It is in numeric format)&amp;nbsp; - Ex:&amp;nbsp;1925365763.1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My Query -&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table two_weeks as&amp;nbsp;&lt;BR /&gt;select a.memberid,&amp;nbsp;a.callid,count(*)&lt;BR /&gt;from &lt;BR /&gt;table1 a inner join table2 b &lt;BR /&gt;on a.memberid = b.memberid&lt;BR /&gt;and b.datetime1 &amp;gt;= (a.max_datetime2 + 2 weeks )&lt;BR /&gt;group by a.memberid, a.callid&lt;BR /&gt;;&lt;BR /&gt;Quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Ana&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 01:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-weeks-to-the-max-of-the-date-and-comparing-it-with/m-p/737792#M230041</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-29T01:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: adding weeks to the max of the date and comparing it with datetimefield</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-weeks-to-the-max-of-the-date-and-comparing-it-with/m-p/737799#M230042</link>
      <description>Thank you. I am trying to see the max_datetime2 field  in YYMMDDn8 format and add 14 days to test the above solution.Date3 is resolving to blank answer.&lt;BR /&gt;&lt;BR /&gt;Data test;&lt;BR /&gt;date3 = input(put(1925365763.1,yymmddn8.),8.);&lt;BR /&gt;run;</description>
      <pubDate>Thu, 29 Apr 2021 03:01:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-weeks-to-the-max-of-the-date-and-comparing-it-with/m-p/737799#M230042</guid>
      <dc:creator>SASAna</dc:creator>
      <dc:date>2021-04-29T03:01:14Z</dc:date>
    </item>
    <item>
      <title>Re: adding weeks to the max of the date and comparing it with datetimefield</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-weeks-to-the-max-of-the-date-and-comparing-it-with/m-p/737801#M230043</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/86567"&gt;@SASAna&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you. I am trying to see the max_datetime2 field in YYMMDDn8 format and add 14 days to test the above solution.Date3 is resolving to blank answer.&lt;BR /&gt;&lt;BR /&gt;Data test;&lt;BR /&gt;date3 = input(put(1925365763.1,yymmddn8.),8.);&lt;BR /&gt;run;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This does not make much sense at all.&amp;nbsp; Let's look at what that those function calls are doing.&lt;/P&gt;
&lt;P&gt;First you are trying to use the PUT() to convert the number&amp;nbsp;1,925,365,763.1 into a string using the YYMMDDN8. format.&amp;nbsp; If we divide that giant number by the number of days in a year and add it to the base year that SAS uses for day number zero we get a year that would require way more than 4 digits to represent.&lt;/P&gt;
&lt;PRE&gt;806   data test;
807     days = 1925365763 ;
808     years = 1960 + int(days/365.25) ;
809     put (_all_) (=comma15.);
810   run;

days=1,925,365,763 years=5,273,324
&lt;/PRE&gt;
&lt;P&gt;Now lets look at the other function call does.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First we assume that you actually generated string in YYYYMMDD style, for example day's date in that style would be the string "20210428".&amp;nbsp; So if you convert that string to a number by reading the first 8 bytes then you would get the number 20,210,428.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are you going to do with this number?&lt;/P&gt;
&lt;P&gt;And why would you assign it to a variable with a name like DATE3?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps the number&amp;nbsp;1,925,365,763.1&amp;nbsp; was really a datetime value (number of seconds since 1960)?&amp;nbsp; Lets see what it looks like when formatted as a datetime value.&lt;/P&gt;
&lt;PRE&gt;811   data test;
812     seconds  = 1925365763 ;
813     put seconds = comma15. '-&amp;gt; ' seconds datetime20. ;
814   run;

seconds=1,925,365,763 -&amp;gt;   04JAN2021:07:49:23
&lt;/PRE&gt;
&lt;P&gt;So that is some time on the morning of January 4th of this year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to convert that to a date you can use the DATEPART() function.&lt;/P&gt;
&lt;PRE&gt;815   data test;
816     seconds  = 1925365763 ;
817     days = datepart(seconds);
818     put seconds = comma15. '-&amp;gt; ' seconds datetime20. ;
819     put days = comma15. '-&amp;gt; ' days date9. ;
820   run;

seconds=1,925,365,763 -&amp;gt;   04JAN2021:07:49:23
days=22,284 -&amp;gt; 04JAN2021
&lt;/PRE&gt;
&lt;P&gt;If you want the date to print in that YYYYMMDD style then use the YYMMDDN8. format instead of the DATE9. format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if you really did want to store the number 20,210,104 into a numeric variable like original input(put()) function call appeared to want to do you could use:&lt;/P&gt;
&lt;PRE&gt;827   data test;
828     seconds  = 1925365763 ;
829     date_integer = input(put(datepart(seconds),yymmddn8.),8.);
830     put seconds = comma15. '-&amp;gt; ' seconds datetime20. ;
831     put date_integer = '-&amp;gt; ' date_integer comma15.;
832   run;

seconds=1,925,365,763 -&amp;gt;   04JAN2021:07:49:23
date_integer=20210104 -&amp;gt;      20,210,104
&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Apr 2021 03:26:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-weeks-to-the-max-of-the-date-and-comparing-it-with/m-p/737801#M230043</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-29T03:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: adding weeks to the max of the date and comparing it with datetimefield</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-weeks-to-the-max-of-the-date-and-comparing-it-with/m-p/737893#M230090</link>
      <description>Thanks for the explanation. It helped me for testing.</description>
      <pubDate>Thu, 29 Apr 2021 13:14:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-weeks-to-the-max-of-the-date-and-comparing-it-with/m-p/737893#M230090</guid>
      <dc:creator>SASAna</dc:creator>
      <dc:date>2021-04-29T13:14:26Z</dc:date>
    </item>
    <item>
      <title>Re: adding weeks to the max of the date and comparing it with datetimefield</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-weeks-to-the-max-of-the-date-and-comparing-it-with/m-p/737894#M230091</link>
      <description>Thanks Reeza, it worked well.</description>
      <pubDate>Thu, 29 Apr 2021 13:15:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-weeks-to-the-max-of-the-date-and-comparing-it-with/m-p/737894#M230091</guid>
      <dc:creator>SASAna</dc:creator>
      <dc:date>2021-04-29T13:15:09Z</dc:date>
    </item>
  </channel>
</rss>

