11-09-2016 05:17 AM
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?
11-09-2016 05:44 AM
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.
11-09-2016 05:48 AM
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!
11-09-2016 05:53 AM
Use NKWDOM() to calculate first Wednesday of month and execute if true.
If nwkdom(1, 4, month(today()), year(today())) = today() then call execute('%include "path to program"');
11-09-2016 07:15 AM
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
11-09-2016 07:16 AM
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
Need further help from the community? Please ask a new question.