<?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 last thursday in month in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-last-thursday-in-month/m-p/625119#M184228</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;ans&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much. Both solutions work very well, but I accept&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;'s solution, because he made me aware of the nwkdom function specially designed to do the job.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I strive for keeping myself updated on "what's new" in SAS versions, so I should have known, but there has been so many "what's news" since my introduction to SAS with version 79, and I tend to forget the smart features again, if I don't have any immediate use for them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried to understand &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;'s solution using intnx function. I never tried using modifiers on the interval type, and I can see that it works, but it doesn't make me any wiser, because I cannot understand why. Spending the afternoon on reading the Function Reference documentation of complex time intervals didn't help me much either, so I hope you would take the time to enlighten me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Take as example May 2021. The intnx function intnx() with WEEK1.5 as interval and a increment of 0 has Monday, 31. May as starting point, so I would expect it to return the 5. day of the week containing the starting point, not the fifth day of the previous week.&lt;/P&gt;</description>
    <pubDate>Sun, 16 Feb 2020 14:44:06 GMT</pubDate>
    <dc:creator>ErikLund_Jensen</dc:creator>
    <dc:date>2020-02-16T14:44:06Z</dc:date>
    <item>
      <title>How to calculate last thursday in month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-last-thursday-in-month/m-p/625104#M184222</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;As a follow-up to the discussion about calculating last sunday in month, posted by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/216038"&gt;@Brad39&lt;/a&gt;&amp;nbsp;and answered by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had a similar problem last week. The&amp;nbsp;task was to compute batch run dates for a lot of jobs as&lt;STRONG&gt; tuesday after last thursday&lt;/STRONG&gt; in every month.&amp;nbsp;I solved it with a "brute force" approach, but I am sure it can be done smarter, and it bothers me that I couldn't find a more elegant solution myself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* calculate tuesday after last thursday in months 202001 - 202112;
data want (drop=weekday i); 
	format actual_date month_last last_thursday run_date nldatew30.;

	do y = 2020 to 2021;
		do m = 1 to 12;
			actual_date = mdy(m,1,y);

			month_last = intnx('month',actual_date,0,'e');
			weekday = weekday(month_last);
			do i = 0 to 7;
				last_thursday = month_last - i;
				weekday = weekday(last_thursday);
				if weekday = 5 then leave;
				last_thursday = month_last - i;
			end;
			run_date = last_thursday + 5;
			output;

		end;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Feb 2020 10:51:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-last-thursday-in-month/m-p/625104#M184222</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2020-02-16T10:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate last thursday in month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-last-thursday-in-month/m-p/625106#M184224</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12887"&gt;@ErikLund_Jensen&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one approach:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop= y m); 
	format run_date nldatew30.;

	do y = 2020 to 2021;
		do m = 1 to 12;
			run_date=intnx('week1.5',intnx('month',mdy(m,1,y),0,'e'),0) + 5;
			output;
		end;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 16 Feb 2020 11:47:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-last-thursday-in-month/m-p/625106#M184224</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-16T11:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate last thursday in month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-last-thursday-in-month/m-p/625114#M184225</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12887"&gt;@ErikLund_Jensen&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wouldn't Ksharp's solution from that other discussion simply suggest:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;run_date=nwkdom(5,5,m,y)+5;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Feb 2020 12:57:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-last-thursday-in-month/m-p/625114#M184225</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-02-16T12:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate last thursday in month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-last-thursday-in-month/m-p/625119#M184228</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;ans&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much. Both solutions work very well, but I accept&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;'s solution, because he made me aware of the nwkdom function specially designed to do the job.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I strive for keeping myself updated on "what's new" in SAS versions, so I should have known, but there has been so many "what's news" since my introduction to SAS with version 79, and I tend to forget the smart features again, if I don't have any immediate use for them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried to understand &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;'s solution using intnx function. I never tried using modifiers on the interval type, and I can see that it works, but it doesn't make me any wiser, because I cannot understand why. Spending the afternoon on reading the Function Reference documentation of complex time intervals didn't help me much either, so I hope you would take the time to enlighten me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Take as example May 2021. The intnx function intnx() with WEEK1.5 as interval and a increment of 0 has Monday, 31. May as starting point, so I would expect it to return the 5. day of the week containing the starting point, not the fifth day of the previous week.&lt;/P&gt;</description>
      <pubDate>Sun, 16 Feb 2020 14:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-last-thursday-in-month/m-p/625119#M184228</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2020-02-16T14:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate last thursday in month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-last-thursday-in-month/m-p/625123#M184232</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12887"&gt;@ErikLund_Jensen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Take as example May 2021. The intnx function intnx() with WEEK1.5 as interval and a increment of 0 has Monday, 31. May as starting point, so I would expect it to return the 5. day of the week containing the starting point, not the fifth day of the previous week.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The logic here is: The first argument &lt;FONT face="courier new,courier"&gt;'WEEK1.5'&lt;/FONT&gt; (or equivalently&amp;nbsp;&lt;FONT face="courier new,courier"&gt;'WEEK.5'&lt;/FONT&gt;)&amp;nbsp; specifies that week intervals will be considered which are shifted (by four days) so that they start on Thursday (=5th weekday for SAS) rather than Sunday (=1st weekday, the default). So, in your example we are looking at the 7-day interval, Thursday to Wednesday, containing the 31 May 2021. We don't increment it (third argument 0) and just take the first day of this interval (&lt;FONT face="courier new,courier"&gt;'BEGINNING'&lt;/FONT&gt; is the default for the &lt;FONT face="courier new,courier"&gt;'&lt;EM&gt;alignment&lt;/EM&gt;'&lt;/FONT&gt; argument). The result is necessarily the last Thursday of the same month, i.e. 27 May 2021.&lt;/P&gt;</description>
      <pubDate>Sun, 16 Feb 2020 17:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-last-thursday-in-month/m-p/625123#M184232</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-02-16T17:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate last thursday in month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-last-thursday-in-month/m-p/625126#M184233</link>
      <description>I understand it now thanks to your explanation.</description>
      <pubDate>Sun, 16 Feb 2020 18:51:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-last-thursday-in-month/m-p/625126#M184233</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2020-02-16T18:51:33Z</dc:date>
    </item>
  </channel>
</rss>

