Run a %include statement only in the first week of the month

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Run a %include statement only in the first week of the month

I run a script every wednesday. What I would like to do is at the bottom of that script have a %include statement to call an additional program, but to only run this additional programme if it is the first wednesday of the month. I'm not sure how to create a conditional %include statement based on dates. Does anyone have any thoughts they could help me with?

Many thanks.


Accepted Solutions
Solution
‎11-15-2016 04:07 AM
Super User
Posts: 5,509

Re: Run a %include statement only in the first week of the month

Also untested, but perhaps simpler:

 

if day(today()) < 8 and weekday(today())=4 then %include '........';

View solution in original post


All Replies
Super User
Super User
Posts: 7,963

Re: Run a %include statement only in the first week of the month

The first question I would ask is why?  I have never seen a reason to run code conditionally based on a date, it just sounds like bad setup.  How are you running the code now?  Is it scheduled, if so then have the two separate schedules, one that runs both programs on first wed in month, the other to run all others.  Although that being said, the question still is why, what special thing happens on that day, and why can't it just be included in your project, is it a missing file, if so just check for file existence, etc.

New Contributor
Posts: 3

Re: Run a %include statement only in the first week of the month

We have limited schedulers we can run across our clients server,  but also for ease of use and filekeeping, I'd like to know if it can be done!

Super User
Posts: 19,815

Re: Run a %include statement only in the first week of the month

Use NKWDOM() to calculate first Wednesday of month and execute if true. 

 

Untested:

 

If nwkdom(1, 4, month(today()), year(today())) = today() then call execute('%include "path to program"');

 

 

New Contributor
Posts: 3

Re: Run a %include statement only in the first week of the month

HI Reeza - couldn't quite get the function to work but have played around with calculating the day of the month and it runs the %include statement perfectly! Thank you sooooo much for being so helpful Smiley Happy

SAS Super FREQ
Posts: 708

Re: Run a %include statement only in the first week of the month

The NWKDOM function was already mentioned.

 

Here is a version packaged in a macro

 

filename mypgm temp;

data _null_;
  file mypgm;
  put "proc print data=sashelp.class;";
  put "run;";
run;

%macro run_1st_wed;
  %local 
    today
    first_wed
  ;
  %let today = %sysfunc( today() );
  %let first_wed = %sysfunc( nwkdom(1, 4, %sysfunc(month(&today)), %sysfunc(year(&today))) );

  %if &today = &first_wed %then %do;
    %put NOTE: &sysmacroname running;
    %include mypgm;
  %end;
  %else %do;
    %put NOTE: &sysmacroname &today = &first_wed does not match;
  %end;

%mend;

%run_1st_wed
Solution
‎11-15-2016 04:07 AM
Super User
Posts: 5,509

Re: Run a %include statement only in the first week of the month

Also untested, but perhaps simpler:

 

if day(today()) < 8 and weekday(today())=4 then %include '........';

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 430 views
  • 2 likes
  • 5 in conversation