<?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: Execute the code on the first weekday of the month in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Execute-the-code-on-the-first-weekday-of-the-month/m-p/488092#M127212</link>
    <description>&lt;PRE&gt;If I were you, I'd include one-byte Boolean fields in your calendar table, like 
Business day 
Week-end day 
Holiday day 
First calendar day of the calendar year 
First calendar day of the fiscal year 
First calendar day of the quarter 
First calendar day of the month 
First calendar day of the week 
First business day of the quarter 
First business day of the month 
First business day of the week 
Second calendar day of the quarter 
Second calendar day of the month 
Second calendar day of the week 
Second business day of the quarter 
Second business day of the month 
Second business day of the week 
Last calendar day of the quarter 
Last calendar day of the month 
Last calendar day of the week 
Last business day of the quarter 
Last business day of the month 
Last business day of the week 
etc 
This would make scheduling anything at all very easy. 
Alternatively, you could store these as formats and apply the format on the date.
&lt;/PRE&gt;</description>
    <pubDate>Mon, 20 Aug 2018 03:02:24 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2018-08-20T03:02:24Z</dc:date>
    <item>
      <title>Execute the code on the first weekday of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-the-code-on-the-first-weekday-of-the-month/m-p/488083#M127208</link>
      <description>Hi,&lt;BR /&gt;I have this SAS program which is supposed to be run monthly on the first weekday of the month. It has been scheduled to run daily through cron.&lt;BR /&gt;Is there a way I can wrap this program in a macro that will execute only if it is the first weekday of the month otherwise will exit. Also to account for public/business holidays I have a calendar dataset which looks like this.&lt;BR /&gt;Date Bus_ind Day_cd&lt;BR /&gt;1/1/2018 0 New Year’s Day&lt;BR /&gt;1/2/2018 1 Workday&lt;BR /&gt;1/3/2018 1 Workday&lt;BR /&gt;1/4/2018 1 Workday&lt;BR /&gt;1/5/2018 1 Workday&lt;BR /&gt;1/6/2018 0 Weekend&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Any suggestions or code example is highly appreciated.&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Sun, 19 Aug 2018 23:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-the-code-on-the-first-weekday-of-the-month/m-p/488083#M127208</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2018-08-19T23:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: Execute the code on the first weekday of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-the-code-on-the-first-weekday-of-the-month/m-p/488092#M127212</link>
      <description>&lt;PRE&gt;If I were you, I'd include one-byte Boolean fields in your calendar table, like 
Business day 
Week-end day 
Holiday day 
First calendar day of the calendar year 
First calendar day of the fiscal year 
First calendar day of the quarter 
First calendar day of the month 
First calendar day of the week 
First business day of the quarter 
First business day of the month 
First business day of the week 
Second calendar day of the quarter 
Second calendar day of the month 
Second calendar day of the week 
Second business day of the quarter 
Second business day of the month 
Second business day of the week 
Last calendar day of the quarter 
Last calendar day of the month 
Last calendar day of the week 
Last business day of the quarter 
Last business day of the month 
Last business day of the week 
etc 
This would make scheduling anything at all very easy. 
Alternatively, you could store these as formats and apply the format on the date.
&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Aug 2018 03:02:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-the-code-on-the-first-weekday-of-the-month/m-p/488092#M127212</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-20T03:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: Execute the code on the first weekday of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-the-code-on-the-first-weekday-of-the-month/m-p/488114#M127223</link>
      <description>&lt;P&gt;If you have a scheduler setup to run the program at a given moment, why are you then running it all the time and coding in a check to only run it at a certain timepoint?&amp;nbsp; That is the purpose of the scheduler, so fix the scheduler to run the code only when you want to.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 07:34:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-the-code-on-the-first-weekday-of-the-month/m-p/488114#M127223</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-20T07:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: Execute the code on the first weekday of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-the-code-on-the-first-weekday-of-the-month/m-p/488117#M127225</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;, but sometimes you really want to make sure the program is not run on wrong dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code checks if today is runday. If you have another variable telling which day you are running, just change today() to that variable &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Think this small example will work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dates;
 length Date Bus_ind 8 ;
 format date yymmdd10.;
 informat date anydtdte.;
 input date bus_ind;
 datalines;
1/1/2018 0 New Years Day
1/2/2018 1 Workday
1/3/2018 1 Workday
1/4/2018 1 Workday
1/5/2018 1 Workday
1/6/2018 0 Weekend
20/8/2018 1 Test
;
run;

%let runnow = 0;


data runnow;
 set dates;
 where date = today();
 if bus_ind then run = 1;
 else run = 0;
 call symput('runnow',run);
run;

%put &amp;amp;runnow;

%if &amp;amp;runnow %then %do;
 %put *** Job execution day! ***;
/* code that should be executed */
%end;
%else %do;
 %put *** Job will not run today since it is not marked to do so in the calender :) ! ***;
%end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;//Fredrik&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 07:58:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-the-code-on-the-first-weekday-of-the-month/m-p/488117#M127225</guid>
      <dc:creator>FredrikE</dc:creator>
      <dc:date>2018-08-20T07:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: Execute the code on the first weekday of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-the-code-on-the-first-weekday-of-the-month/m-p/488118#M127226</link>
      <description>&lt;P&gt;First not considering holidays - you could built on that to get more automation. So if it is a holiday add + 1 to the current date and if it is not a saturday or sunday then execute:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
 firstOfMonth =  intnx('month', date(), 0);
 dayOfWeek = weekday(firstOfMonth);
 * Sunday;
 if dayOfWeek = 1 then firstWorkDay = firstOfMonth + 1;
 * Saturday;
 else if dayOfWeek = 2 then firstWorkDay = firstofMonth + 2;
 else firstWorkDay = firstOfMonth;
 if date() eq firstOfMonth then
	do;
		put "Macro Execution";
	end;
 else put "Not first busisnessday";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you are already creating a table why not just create one which has the date of the first businessday for each month and then just check against that table. Let's say that table as the column date_firstBusinessDay which contains the SAS date value for the first business day for each month. Sure you would have to redo this table each year with the new values but getting around holidays is not an easy task.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
 set businessDayTable;
 if date_firstBusinessDay eq date() then
	do;
		put "Macro Execution";
	end;
 else put "Not first business day";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 07:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-the-code-on-the-first-weekday-of-the-month/m-p/488118#M127226</guid>
      <dc:creator>Criptic</dc:creator>
      <dc:date>2018-08-20T07:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Execute the code on the first weekday of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-the-code-on-the-first-weekday-of-the-month/m-p/488123#M127229</link>
      <description>&lt;P&gt;One possibility is to extract the run dates from your calendar, like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data rundates(index=(date));
  set calendar;
  where bus_ind=1;
  if month(date) ne month(lag(date));
  keep date;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then, in the top of your batch program put a datastep like this;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  date=today();
  set rundates key=date;
  if _iorc_ then do;
    put 'Today is not first business day of month, aborting';
    _error_=0;
    abort return 0;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Of course, you will want to store you rundates table in a permanent library.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 08:11:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-the-code-on-the-first-weekday-of-the-month/m-p/488123#M127229</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-08-20T08:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: Execute the code on the first weekday of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-the-code-on-the-first-weekday-of-the-month/m-p/488570#M127366</link>
      <description>&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;year=year(date);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;month=month(date);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;if&amp;nbsp; date=nwkdom(1, 2, month, year) then output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 14:12:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-the-code-on-the-first-weekday-of-the-month/m-p/488570#M127366</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-08-21T14:12:54Z</dc:date>
    </item>
  </channel>
</rss>

