<?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: To find the 1st working day of a month in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/293931#M61287</link>
    <description>&lt;P&gt;Thanks for your guidance, I will try to apply and see if I could get the logic working correctly.Thanks once again!!!&lt;/P&gt;</description>
    <pubDate>Thu, 25 Aug 2016 04:52:11 GMT</pubDate>
    <dc:creator>lakshmiG</dc:creator>
    <dc:date>2016-08-25T04:52:11Z</dc:date>
    <item>
      <title>To find the 1st working day of a month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/293924#M61281</link>
      <description>&lt;P&gt;Dear Friends,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the following code to find the beginning week day of every month, I am taking the latest daily data available in our database which is from&amp;nbsp; June 2016.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do i=0 %to 2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; first_day_&amp;amp;i = intnx('weekday',intnx('month',day,-&amp;amp;i,'b'),0);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; format first_day_&amp;amp;i yymmdd10.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if date = first_day_&amp;amp;i then output;&lt;BR /&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, now I need values from APR2016 to JUN2016 (3 month values, code has to be automated to run to pick latest 3 months for current data) , so, 1st working day of June which is 01JUNE2016 and SAS could able to recognise and giving correct output, also for April 01APR2016 is weekday and its picking correctly. But for May2016, 1st is sunday and 2nd, Monday is a public holiday, so the date in database starts from 03May2016,&amp;nbsp; SAS instead to take 03MAY2016, it is considering 29APR2016, which is Friday of previous month, Why it is checking in previous month?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please advise and guide me on this issue.&lt;/P&gt;&lt;P&gt;I need 03May2016 value as the output.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Aug 2016 03:49:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/293924#M61281</guid>
      <dc:creator>lakshmiG</dc:creator>
      <dc:date>2016-08-25T03:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: To find the 1st working day of a month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/293929#M61285</link>
      <description>&lt;PRE&gt;
First of all , you need to know which date are Holidays , then Apply the following code:



data _null_;
x='01may2016'd;
first=intnx('weekday',x,0);
if weekday(first) in (1 6) then first=intnx('weekday',x,1);
/*
If first is holiday then do something here ........
*/
put x= date9. first= date9.;


x='01aug2016'd;
first=intnx('weekday',x,0);
if weekday(first) in (1 6) then first=intnx('weekday',x,1);
put x= date9. first= date9.;
run;

&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Aug 2016 04:36:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/293929#M61285</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-25T04:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: To find the 1st working day of a month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/293931#M61287</link>
      <description>&lt;P&gt;Thanks for your guidance, I will try to apply and see if I could get the logic working correctly.Thanks once again!!!&lt;/P&gt;</description>
      <pubDate>Thu, 25 Aug 2016 04:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/293931#M61287</guid>
      <dc:creator>lakshmiG</dc:creator>
      <dc:date>2016-08-25T04:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: To find the 1st working day of a month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/293943#M61293</link>
      <description>&lt;P&gt;SAS has the NWKDOM function that can give you back the first monday in a month. See the sample below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Whether a date is a holiday that needs to come from somewhere else as it might be country and region dependant.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  year = year(today());
  do month = 1 to 12;
    firstDayMonth = mdy(month, 1, year);
    firstWorkDay = NWKDOM(1, 2, month, year);
    output;
  end;
  format first: weekdate.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
      <pubDate>Thu, 25 Aug 2016 06:12:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/293943#M61293</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2016-08-25T06:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: To find the 1st working day of a month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/293951#M61297</link>
      <description>&lt;P&gt;Here is a version for the first work day in the month&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do year = year(today())-1 to year(today());
    do month = 1 to 12;
      firstDayMonth = mdy(month, 1, year);
      firstMonday = NWKDOM(1, 2, month, year);

      if day(firstMonday) &amp;lt;= 3 then do;
        firstWorkDay = firstMonday;
      end;
      else do;
        firstWorkDay = intnx('weekday17w',firstDayMonth,0);
      end;

      output;
    end;
  end;

  format first: weekdate.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
      <pubDate>Thu, 25 Aug 2016 06:48:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/293951#M61297</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2016-08-25T06:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: To find the 1st working day of a month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/293967#M61302</link>
      <description>&lt;P&gt;Hi Bruno,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Great!!! Thanks for your response and logic. Very interesting to know new logics in SAS.&amp;nbsp; I will use your logic in my coding and check. Thanks much!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Aug 2016 08:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/293967#M61302</guid>
      <dc:creator>lakshmiG</dc:creator>
      <dc:date>2016-08-25T08:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: To find the 1st working day of a month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/293983#M61305</link>
      <description>&lt;PRE&gt;
Sorry. I made a mistake. The first code is not right . Try this one:



data _null_;
x='01aug2015'd;
first=intnx('weekday',x,0);
if month(first) ne month(x) then first=intnx('weekday',x,1);
/*
If first is holiday then do something here ........
*/
put x= date9. first= date9.;


x='01jul2016'd;
first=intnx('weekday',x,0);
if month(first) ne month(x) then first=intnx('weekday',x,1);
put x= date9. first= date9.;
run;




&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Aug 2016 11:47:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/293983#M61305</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-25T11:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: To find the 1st working day of a month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/294294#M61384</link>
      <description>&lt;P&gt;Great!!! Thanks much Xia Keshan for your wonderful support!!!&lt;/P&gt;&lt;P&gt;I will try this.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2016 07:49:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/294294#M61384</guid>
      <dc:creator>lakshmiG</dc:creator>
      <dc:date>2016-08-26T07:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: To find the 1st working day of a month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/294303#M61390</link>
      <description>&lt;PRE&gt;
If you only care about the first day of each month, That might be easy.


data _null_;
x='01aug2015'd;
first=intnx('weekday',x,0);
if month(first) ne month(x) then first=intnx('weekday',x,1);
if weekday(x) in (1 7) then first=first+1;
put x= date9. first= date9.;


x='01may2016'd;
first=intnx('weekday',x,0);
if month(first) ne month(x) then first=intnx('weekday',x,1);
if weekday(x) in (1 7) then first=first+1;
put x= date9. first= date9.;
run;


&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Aug 2016 08:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-find-the-1st-working-day-of-a-month/m-p/294303#M61390</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-26T08:33:52Z</dc:date>
    </item>
  </channel>
</rss>

