<?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 get start and end date of the previous week of the month in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-start-and-end-date-of-the-previous-week-of-the-month/m-p/521060#M141341</link>
    <description>&lt;P&gt;Woww!!! you save my day&amp;nbsp;&lt;SPAN class="login-bold"&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/160362" target="_self"&gt;ShiroAmada&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;but can you explain a little bit what the below script doing:-&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;weekday&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;start&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt; or &lt;SPAN class="token function"&gt;day&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;start&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;end&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;lag&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;start&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;-1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks once more&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Dec 2018 04:34:32 GMT</pubDate>
    <dc:creator>imza72</dc:creator>
    <dc:date>2018-12-13T04:34:32Z</dc:date>
    <item>
      <title>How to get start and end date of the previous week of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-start-and-end-date-of-the-previous-week-of-the-month/m-p/521045#M141336</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I need to run a weekly report of the month every monday.&lt;/P&gt;&lt;P&gt;Let say now month is December.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first report I need to run is on Monday (3rd-Dec-2018) which is fall in Week2 of Dec.&lt;/P&gt;&lt;P&gt;How I'm going to get the start and end date of the previous week?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is when the report should be run/generated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Week1 report will be run in Monday Week2 :&amp;nbsp;&lt;STRONG&gt;start=01-DEC-2018 , end=02-DEC-2018&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Week2 report will be run in Monday&amp;nbsp;Week3 :&amp;nbsp;&lt;STRONG&gt;start=03-DEC-2018&amp;nbsp;,&amp;nbsp;end=09-DEC-2018&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Week3 report will be run in Monday&amp;nbsp;Week4 :&amp;nbsp;&lt;STRONG&gt;start=10-DEC-2018&amp;nbsp;,&amp;nbsp;end=16-DEC-2018&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Week4 report will be run in Monday&amp;nbsp;Week5 :&amp;nbsp;&lt;STRONG&gt;start=17-DEC-2018&amp;nbsp;,&amp;nbsp;end=23-DEC-2018&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Week5 report will be run in Monday&amp;nbsp;Week6 :&amp;nbsp;&lt;STRONG&gt;start=24-DEC-2018&amp;nbsp;,&amp;nbsp;end=30-DEC-2018&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Week6 report will be run in&amp;nbsp;&lt;SPAN&gt;Monday&amp;nbsp;&lt;/SPAN&gt; Week1 of the following month. In this case Jan 2019 :&amp;nbsp;&lt;STRONG&gt;start=31-DEC-2018&amp;nbsp;,&amp;nbsp;end=31-DEC-2018&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 01:36:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-start-and-end-date-of-the-previous-week-of-the-month/m-p/521045#M141336</guid>
      <dc:creator>imza72</dc:creator>
      <dc:date>2018-12-13T01:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to get start and end date of the previous week of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-start-and-end-date-of-the-previous-week-of-the-month/m-p/521052#M141337</link>
      <description>&lt;P&gt;You will need to become familiar with the INTNX function.&amp;nbsp; Here is one way.&amp;nbsp; Within a DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;start = intnx('week', today(), 0) +1;&lt;/P&gt;
&lt;P&gt;end = start + 6;&lt;/P&gt;
&lt;P&gt;format start end date9.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This won't take care of the first week, because that one follows different rules&amp;nbsp; (using a two-day time period).&amp;nbsp; You will have to hard-code the dates for the first week.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise, you just have to run the program on a weekday to get the proper time period.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 03:02:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-start-and-end-date-of-the-previous-week-of-the-month/m-p/521052#M141337</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-12-13T03:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to get start and end date of the previous week of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-start-and-end-date-of-the-previous-week-of-the-month/m-p/521054#M141338</link>
      <description>&lt;P&gt;thank you. will try.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 03:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-start-and-end-date-of-the-previous-week-of-the-month/m-p/521054#M141338</guid>
      <dc:creator>imza72</dc:creator>
      <dc:date>2018-12-13T03:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to get start and end date of the previous week of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-start-and-end-date-of-the-previous-week-of-the-month/m-p/521058#M141340</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have(where=(weekday(start)=2 or day(start)=1));
format start end date9.;
  do start='01Dec2018'd to '31Mar2019'd;
      output;
  end;
run;

proc sort data=have;
  by descending start ;
  run;

data have;
  set have;
  end=lag(start)-1;
  if _n_=1 then end=intnx('month',start,0,'e');
run;

proc sort data=have out=want;
  by  start ;
  run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Dec 2018 04:09:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-start-and-end-date-of-the-previous-week-of-the-month/m-p/521058#M141340</guid>
      <dc:creator>ShiroAmada</dc:creator>
      <dc:date>2018-12-13T04:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to get start and end date of the previous week of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-start-and-end-date-of-the-previous-week-of-the-month/m-p/521060#M141341</link>
      <description>&lt;P&gt;Woww!!! you save my day&amp;nbsp;&lt;SPAN class="login-bold"&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/160362" target="_self"&gt;ShiroAmada&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;but can you explain a little bit what the below script doing:-&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;weekday&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;start&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt; or &lt;SPAN class="token function"&gt;day&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;start&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;end&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;lag&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;start&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;-1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks once more&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 04:34:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-start-and-end-date-of-the-previous-week-of-the-month/m-p/521060#M141341</guid>
      <dc:creator>imza72</dc:creator>
      <dc:date>2018-12-13T04:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to get start and end date of the previous week of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-start-and-end-date-of-the-previous-week-of-the-month/m-p/521064#M141342</link>
      <description>&lt;P&gt;I wanted to filter the records in the output dataset.&amp;nbsp; In the data statement data have(where=(weekday(start)=2 or day(start)=1)); I used the sas functions&amp;nbsp;WEEKDAY, LAG&amp;nbsp;and DAY.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WEEKDAY function will extract the day of the week (in the date variable),&amp;nbsp;&amp;nbsp;result is 1 to 7 (1-Sunday and 7-Saturday).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DAY function is the actual day&amp;nbsp;extracted from the date value (i.e 31Dec2018 will give you 31).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LAG function will copy the value of top record as it's value.&amp;nbsp; This is why I sorted the dates in descending order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As mentioned by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;getting to know SAS functions (like INTNX) will help.&amp;nbsp; The program I created made use of the sas functions WEEKDAY, DAY, LAG and INTNX.&amp;nbsp; Check out these functions and see how to will help you in the future.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Glad I was able to help you out.&amp;nbsp; Cheers!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 04:55:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-start-and-end-date-of-the-previous-week-of-the-month/m-p/521064#M141342</guid>
      <dc:creator>ShiroAmada</dc:creator>
      <dc:date>2018-12-13T04:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to get start and end date of the previous week of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-start-and-end-date-of-the-previous-week-of-the-month/m-p/521065#M141343</link>
      <description>thanks for your promtpresponse</description>
      <pubDate>Thu, 13 Dec 2018 04:59:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-start-and-end-date-of-the-previous-week-of-the-month/m-p/521065#M141343</guid>
      <dc:creator>imza72</dc:creator>
      <dc:date>2018-12-13T04:59:23Z</dc:date>
    </item>
  </channel>
</rss>

