<?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 How to extract weekday from previous month in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-weekday-from-previous-month-in-SAS/m-p/537657#M147902</link>
    <description>&lt;P&gt;How to get the date of 1st monday from previous month of today's date in SAS.&lt;/P&gt;&lt;P&gt;i.e: if today is 22ndFeb2019 then i need 7thJan2019 as output.&lt;/P&gt;</description>
    <pubDate>Fri, 22 Feb 2019 13:13:47 GMT</pubDate>
    <dc:creator>aman23</dc:creator>
    <dc:date>2019-02-22T13:13:47Z</dc:date>
    <item>
      <title>How to extract weekday from previous month in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-weekday-from-previous-month-in-SAS/m-p/537657#M147902</link>
      <description>&lt;P&gt;How to get the date of 1st monday from previous month of today's date in SAS.&lt;/P&gt;&lt;P&gt;i.e: if today is 22ndFeb2019 then i need 7thJan2019 as output.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Feb 2019 13:13:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-weekday-from-previous-month-in-SAS/m-p/537657#M147902</guid>
      <dc:creator>aman23</dc:creator>
      <dc:date>2019-02-22T13:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract weekday from previous month in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-weekday-from-previous-month-in-SAS/m-p/537664#M147904</link>
      <description>&lt;P&gt;Well, intnx() moves a date by a given period.&amp;nbsp; That will get you someways, then you just need to find the next monday.&amp;nbsp; Maybe;&lt;/P&gt;
&lt;PRE&gt;data want;
  last_month=intnx('month',today(),-1,'b');
  do while(weekday(last_month) ne 2);
    last_month=last_month+1;
  end;  
  format last_month date9.;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Feb 2019 13:32:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-weekday-from-previous-month-in-SAS/m-p/537664#M147904</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-22T13:32:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract weekday from previous month in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-weekday-from-previous-month-in-SAS/m-p/537668#M147907</link>
      <description>&lt;P&gt;Use intnx (as suggested by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; ) to get a valid date for last month, then use function nwkdom to get the first monday.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	lastMonth = intnx('MONTH', today(), -1, 's');
	pmm = nwkdom(1, 2, month(lastMonth), year(lastMonth));
	put pmm date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Feb 2019 13:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-weekday-from-previous-month-in-SAS/m-p/537668#M147907</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-02-22T13:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract weekday from previous month in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-weekday-from-previous-month-in-SAS/m-p/537670#M147908</link>
      <description>&lt;P&gt;Nice, never used nwkdom()!&lt;/P&gt;</description>
      <pubDate>Fri, 22 Feb 2019 13:40:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-weekday-from-previous-month-in-SAS/m-p/537670#M147908</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-22T13:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract weekday from previous month in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-weekday-from-previous-month-in-SAS/m-p/537676#M147910</link>
      <description>&lt;P&gt;You can do this in a formula by doing a double mod():&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
format prev_month yymmddd10.;
do i = -1 to -24 by -1;
  prev_month = intnx('month',today(),i,'b');
  prev_month = prev_month + mod(mod(2-weekday(prev_month),7)+7,7);
  x1 = weekday(prev_month);
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I used a loop to show that it always results in weekday of 2 (Monday).&lt;/P&gt;</description>
      <pubDate>Fri, 22 Feb 2019 13:54:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-weekday-from-previous-month-in-SAS/m-p/537676#M147910</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-22T13:54:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract weekday from previous month in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-weekday-from-previous-month-in-SAS/m-p/537678#M147912</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Use intnx (as suggested by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; ) to get a valid date for last month, then use function nwkdom to get the first monday.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	lastMonth = intnx('MONTH', today(), -1, 's');
	pmm = nwkdom(1, 2, month(lastMonth), year(lastMonth));
	put pmm date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Use intnx (as suggested by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; ) to get a valid date for last month, then use function nwkdom to get the first monday.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	lastMonth = intnx('MONTH', today(), -1, 's');
	pmm = nwkdom(1, 2, month(lastMonth), year(lastMonth));
	put pmm date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Maxim 9 at work again &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Feb 2019 14:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-weekday-from-previous-month-in-SAS/m-p/537678#M147912</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-22T14:01:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract weekday from previous month in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-weekday-from-previous-month-in-SAS/m-p/537750#M147943</link>
      <description>&lt;P&gt;can you plz explain the code after d while, how it worked or logic that you have used&lt;/P&gt;&lt;P&gt;i.e :&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;do while(weekday(last_month) ne 2);  ( what ne 2 resolved here??)
    last_month=last_month+1;  (why value of last_month incremented by 1??)&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Feb 2019 16:38:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-weekday-from-previous-month-in-SAS/m-p/537750#M147943</guid>
      <dc:creator>aman23</dc:creator>
      <dc:date>2019-02-22T16:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract weekday from previous month in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-weekday-from-previous-month-in-SAS/m-p/537756#M147946</link>
      <description>&lt;OL&gt;
&lt;LI&gt;The result of the weekday function is a number between 1 and 7 (1=Sunday, 7=Saturday). So it tests for Monday&lt;/LI&gt;
&lt;LI&gt;SAS dates are counts of days, so adding 1 to a date means "skip to the next day".&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Fri, 22 Feb 2019 16:52:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-weekday-from-previous-month-in-SAS/m-p/537756#M147946</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-22T16:52:29Z</dc:date>
    </item>
  </channel>
</rss>

