macro to conditionally process a block of code

Reply
Contributor
Posts: 69

macro to conditionally process a block of code

I am trying to modify this code so that it will only execute conditionally on the 2nd business day of the month.

I am not allowed to use the Today() function that is why I have wod variable then resetting it with a +1 to determine the actual day

data _null_;

wod=today()-1;

call symput("wod",wod);

call symput("today",put(wod+1,BEST6.)); /** variable used to determine what today’s actual date is **/

run;

   This was used to determine if the 1st of the month was a Sunday, but I don't know how to modify for only executing on the 2nd business day of the month - That is the only day this block of code needs to execute.

data _null_;

Format var 1.;

If weekday(&today.) in (2,3,4,5,6,7) then var = 1;

ELSE IF weekday(&today.) = 1 and day(&today.) = 1 then var = 1;

ELSE var = 0;

call symput("runvar",var);run

%macro runday(var);

%if &var = 1 %then %do;

/** put code here **/

%end;

%mend runday;

%runday(var = &runvar);


Thanks

Super User
Posts: 10,500

Re: macro to conditionally process a block of code

Why are you not allowed to use the TODAY() function?

Do your business rules for  defining "business day" take into account any holidays such as New Years Day, Fourth of July or Labor Day (if USA) as potential exceptions?

Contributor
Posts: 69

Re: macro to conditionally process a block of code

the today thing is a business rule, I know I just had to take it out of another report I developed when I went to implement to production. 

Yes I should probably account for holidays also, since most are observed on a Monday, thanks for asking.  So I guess it should be approximately the 2nd day of the month that is a business day not an observed holiday.  Though I don't know of any holidays that re on the 2nd of the month.

Thanks,

Super User
Posts: 6,936

Re: macro to conditionally process a block of code

"the today thing is a business rule,"

So you are asked to run, but not use your feet?

Get yourself a Louisville Slugger and beat some sense into the idiot responsible for that.

Because this:

data _null_;

wod=today()-1;

call symput("wod",wod);

call symput("today",put(wod+1,BEST6.)); /** variable used to determine what today’s actual date is **/

run;

is exactly what you get out of

%let today=%sysfunc(today());

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 69

Re: macro to conditionally process a block of code

Another piece to this puzzle.

In the processing sections that is conditionally run on the 2nd business day of the month, I only need to pull records from the data source for the previous month. 

If this is executing on or about June 2 then I only want to look at records (transactions)  that occurred in May.

Thanks,

Super User
Super User
Posts: 7,401

Re: macro to conditionally process a block of code

Sounds to me more like a problem for your scheduling software - you do use scheduling software yes?  If so set that up to run things as and when you like, then your SAS program only needs to know how to run not when.

As for only pulling certain records, then use intnx e.g:

proc sql;

     create table THEDATA as

     select     *

     from       ALL_DATA

     where    DATE_IN_ALL_DATA >= intnx('month',today(),-1,'same');

quit;

Contributor
Posts: 69

Re: macro to conditionally process a block of code

Can't put it in with a scheduler.  The error check is part of a daily report and I just want it to run that error check on approximately the 2nd business day of the month.  All the other error checks will be daily.

is there a simple way to identify the 2nd business day of the month and have it set a variable to 1 and every other day set it to 0 then I can use that var in my macro.

thanks,

Ask a Question
Discussion stats
  • 6 replies
  • 321 views
  • 1 like
  • 4 in conversation