Conditional processing of Sunday, 1st of Month

Reply
Contributor
Posts: 74

Conditional processing of Sunday, 1st of Month

I need some help, I am writing a program that normally would not run on a Sunday, but if Sunday is the 1st day of the month a batch process would have completed on Saturday and therefore a file was generated and I need to process that file.  Normally there is no batch process on Saturday except when the Saturday is the last day of the month.  This only occurs about 2 times a year.  So in those instances I need to execute on Sunday to process the Saturday file.

My thought is to have the process run daily and if it is a Sunday and the 1st day of the month then to proceed with the rest of the program, other than that if it is any other Sunday to just exit and not execute the rest of the code. 

While I understand this in my head I cannot seem to write the code to do this.  I have researched and seen a lot of suggestions to use a macro somehow, I am very new to macros and the one's I have seen I don't understand, which I don't have to but I also don't know how to incorporate them into my code.

Any assistance you can offer will be greatly appreciated.

Thank you,

Cindy

Valued Guide
Posts: 858

Re: Conditional processing of Sunday, 1st of Month

sunday is weekday = 1 and the first of the month is day 1.  Something like this may help:

if weekday(run_date) = 1 and day(run_date) = 1 then do;

Contributor
Posts: 53

Re: Conditional processing of Sunday, 1st of Month

One idea is to split the conditional processing i.e. the part that must run if it is the first of the month - into a separate program and use a macro if-else to include that program into your current program when necessary. So you do it this way -

Create sub-program as -

%macro pgm2;

< code that should run when it is the 1st of the month and a sunday >

%mend pgm2;

*****************************************************************************************

Include it in your  main program as -

<code which runs everyday>

.

.

.

data _null_;

sunrun = ((today()=intnx('month',today( ),0)) && weekday(today()) ) ;  /* Checks whether today is the first day of the month and a Sunday */

call symput('sunrun'),sunrun);

run;

%if  "&sunrun" eq  "1" %then %do;

%pgm2

%end;

Please note that this is just a solution idea. You may have to modify certain parts to get the program to work.

Super User
Posts: 19,167

Re: Conditional processing of Sunday, 1st of Month

Use call execute and today() to check if the date=1 and weekday(today)=1.

data _null_;

if today()=1 and weekday(today())=1 then call execute('%run_process');

run;

SAS(R) 9.2 Macro Language: Reference

Ask a Question
Discussion stats
  • 3 replies
  • 273 views
  • 0 likes
  • 4 in conversation