Good morning. I would very much appreciate any help someone might give me.
We have a process that runs on the 15th of each month. There is code that is contained within this process and I only want the code to run on the 15th day after the end of each quarter of the year. Our shop can set the code to run on the 15th of each month, or each day, but the code itself must check the date to determine if it is April 15th, July 15th, October 15th or January 15th and only run on those dates.
Attached is the current date definition portion of the code. You can see it does determine the dates (today, current quarter, etc.). However, I guess what I need is for the code to decide if it is the 15th day after the quarter. I could accomplish it with hard coding the month or day but I was hoping someone had a better answer?
Thanks for any help someone could give me.
data params;
attrib
run_date length=8 format = mmddyy10.
beginqtr length=8 format = mmddyy10.
endingqtr length=8 format = mmddyy10.
rep_start_date length=$10
rep_end_date length=$10
file_name_qtr length=$6;
run_date = today();
beginqtr=intnx('qtr',run_date,-1,"BEGIN");
endingqtr=intnx('qtr',run_date,-1,"END");
rep_start_date=put(beginqtr, mmddyy10.);
rep_end_date=put(endingqtr, mmddyy10.);
file_name_qtr=put(beginqtr, yyq6.);
call symput("run_date",run_date);
call symput("beginqtr",beginqtr);
call symput("endingqtr",endingqtr);
call symput("rep_start_date",rep_start_date);
call symput("rep_end_date",rep_end_date);
call symput("file_name_qtr",file_name_qtr);
call symput("file_name_qtr",file_name_qtr);
run;
If given todays date you want to determine the 15th day past the end of the Previous calendar quarter:
data example; prevquarterplus15 = intnx('quarter',today(),-1,'e') + 15; format prevquarterplus15 date9.; run;
Once you remember that dates are number of days it is easy to add 15 to the end of the quarter, which it looks like you already have to the 15th day of the month following the end of the quarter.
If given todays date you want to determine the 15th day past the end of the Previous calendar quarter:
data example; prevquarterplus15 = intnx('quarter',today(),-1,'e') + 15; format prevquarterplus15 date9.; run;
Once you remember that dates are number of days it is easy to add 15 to the end of the quarter, which it looks like you already have to the 15th day of the month following the end of the quarter.
Thank you very much. It's so nice to be able to go to a group of people who know how to solve problems.
Hi Jeff_DOC,
I am not quite sure what degree of "soft-coding" you expect, but here is how you can set up your binary flag (1 indicating 15th day after end of quarter) in a data step:
the_day = ( (month(run_date) in (1,4,7,10) and day(run_date)=15 );
or
the_day = ( mod(month(run_date)-1,3)=0 and day(run_date)=15 );
Does it answer your question?
Hi Leonid.
Yes, it does and thank you. I will also explore this option. I also look forward to reading your blog.
Adding to the excellent advice above from @LeonidBatkhan and @ballardw
Turning dates into text strings and then turning those text strings into macro variables is rarely useful, in fact its almost always a waste of time. Macro variable date values should be unformatted. There are two exceptions that I know of: if you need the date in a TITLE or LABEL, and inserting data into some databases requires dates to be formatted.
@PaigeMiller wrote:
Adding to the excellent advice above from @LeonidBatkhan and @ballardw
Turning dates into text strings and then turning those text strings into macro variables is rarely useful, in fact its almost always a waste of time. Macro variable date values should be unformatted. There are two exceptions that I know of: if you need the date in a TITLE or LABEL, and inserting data into some databases requires dates to be formatted.
Third use: External file names or paths
Thank you for the advice. I would agree with you and it should change. The person who created it wasn't very confident they were getting the correct dates and wanted to "view" them each time to be sure. Now we have to decide what/when/how to change them to what they should be.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.