BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jeff_DOC
Pyrite | Level 9

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

7 REPLIES 7
ballardw
Super User

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.

Jeff_DOC
Pyrite | Level 9

Thank you very much. It's so nice to be able to go to a group of people who know how to solve problems. 

LeonidBatkhan
Lapis Lazuli | Level 10

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?

 

 
Jeff_DOC
Pyrite | Level 9

Hi Leonid.

 

Yes, it does and thank you. I will also explore this option. I also look forward to reading your blog. 

 

 

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
ballardw
Super User

@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

Jeff_DOC
Pyrite | Level 9

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.

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1191 views
  • 6 likes
  • 4 in conversation