Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run a subset of code based on weekday 1

Status
Not open for further replies.

tariqhali2

Technical User
Aug 15, 2011
3
US
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?
 
If I am not wrong you yourself have found the solution
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
 
Thanks for your reply. I know which function to use however, not sure how to use it in a SAS proc. Here is what I've been trying to do but it doesn't seem to work:

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.
 
If you are aware of macros, I wish u can give try with it;
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
 
Using a SAS Macro:

%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;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top