Run a subset of code based on weekday
Run a subset of code based on weekday
(OP)
I have a large set of code that update various datasets daily.
Part of the code need to only run on Mondays so I want to write some kind of an if statement to check for today's date and run only if today is Monday weekday(date)=2?
Part of the code need to only run on Mondays so I want to write some kind of an if statement to check for today's date and run only if today is Monday weekday(date)=2?
RE: Run a subset of code based on weekday
you can use weekday function as weekday(today()) or weekday(&sysdate)
Or else you can create a separate sas code file for that code and schedule is weekly once on monday using some scheduling tool like if u are using UNIX u can schedule on cron tab
sasbuddy
http://sites.google.com/site/sasbuddy/
RE: Run a subset of code based on weekday
data _null_;
If WEEKDAY(TODAY()) = 1 then do;
%Include '\Data\CODE\Reports.sas';
end;
run;
This seem to run no matter what the day is. not sure what I am doing wrong.
Thanks for your help.
RE: Run a subset of code based on weekday
create a macro of the code which u have included in Reports.sas file and call that macro inside if condition.
One more thing instead of '=' sign you can try using eq for comparison.
I hope this would work. Best Luck.
sasbuddy
http://sites.google.com/site/sasbuddy/
RE: Run a subset of code based on weekday
%MACRO Depend ;
%If %SYSFUNC(WEEKDAY(%SYSFUNC(TODAY()))) = 1 %then
%do;
<CODE HERE>
%END ;
%MEND Depend ;
You could also use a call execute:
Data _NULL_ ;
IF WEEKDAY(TODAY())=1 THEN
CALL EXECUTE ("<Code within quotes here>") ;
RUN;