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 afternoon.

 

I would appreciate any help someone could offer.

 

Basically I need to have an older program run for data for the 28th day of each month on the first of the subsequent month. So on May 1 the beginmonth variable needs to allow me to run for data from March 28th to April 28th. I can do the report programming piece but what I can't get correct is to shift the date each month to the correct 28th day. 

 

Here's the old section that will create the variables as they were before. I need to change these to find the 28th of each month, not the beginning or end of the time period as shown.

 

Any help would be greatly appreciated.

 

data params;
attrib
run_date length=8 format = mmddyy10.
beginmonth length=8 format = mmddyy10.
endingmonth length=8 format = mmddyy10.
rep_start_date length=$10
rep_end_date length=$10;

today = put(date(),worddate18.);

run_date = today();
beginmonth=intnx('month',run_date,-2, "BEGIN");
endingmonth=intnx('month',run_date,-1, "END");
rep_start_date=put(beginmonth, mmddyy10.);
rep_end_date=put(endingmonth, mmddyy10.);

call symput("run_date",run_date);
call symput("beginmonth",beginmonth);
call symput("endingmonth",endingmonth);
call symput("rep_start_date",rep_start_date);
call symput("rep_end_date",rep_end_date);
call symput('today',today);
run;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Here's one way to find the 28th of the month preceding any date:

 

data example;
   date = today();
   prior28 = intnx('month',date,-1,'B') + 27;
   put date= date9. prior28= date9.;
run;

The B is the beginning so add 27 to get to 28 since date values are integer numbers of days.

View solution in original post

4 REPLIES 4
ballardw
Super User

Here's one way to find the 28th of the month preceding any date:

 

data example;
   date = today();
   prior28 = intnx('month',date,-1,'B') + 27;
   put date= date9. prior28= date9.;
run;

The B is the beginning so add 27 to get to 28 since date values are integer numbers of days.

Jeff_DOC
Pyrite | Level 9

Since you both gave me a correct answer I flipped a coin (yes, I'm old enough to still carry coins) and Ballardw won!

 

Thanks to you both for being willing to help!

Reeza
Super User

Which macro variables do you need to change?
What do you need them to change to?
Have you looked at the "S" option for alignment of parameter?
You're aware you can add 27 to the start of a month to get the 28th date?
Want the 28th for the previous month? That would be the start of the previous month + 27.

 

data params;

start_date = '01May2021'd;


*run_date = today();
run_date = start_date;

beginmonth=intnx('month',run_date,-2, "B");
endingmonth=intnx('month',run_date,-1, "B");
rep_start_date=put(beginmonth+27, mmddyy10.);
rep_end_date=put(endingmonth+27, mmddyy10.);


run;

proc print data=params;
run;
 
Obs start_date run_date beginmonth endingmonth rep_start_date rep_end_date
1 22401 22401 22340 22371 03/28/2021 04/28/2021

 


@Jeff_DOC wrote:

Good afternoon.

 

I would appreciate any help someone could offer.

 

Basically I need to have an older program run for data for the 28th day of each month on the first of the subsequent month. So on May 1 the beginmonth variable needs to allow me to run for data from March 28th to April 28th. I can do the report programming piece but what I can't get correct is to shift the date each month to the correct 28th day. 

 

Here's the old section that will create the variables as they were before. I need to change these to find the 28th of each month, not the beginning or end of the time period as shown.

 

Any help would be greatly appreciated.

 

data params;
attrib
run_date length=8 format = mmddyy10.
beginmonth length=8 format = mmddyy10.
endingmonth length=8 format = mmddyy10.
rep_start_date length=$10
rep_end_date length=$10;

today = put(date(),worddate18.);

run_date = today();
beginmonth=intnx('month',run_date,-2, "BEGIN");
endingmonth=intnx('month',run_date,-1, "END");
rep_start_date=put(beginmonth, mmddyy10.);
rep_end_date=put(endingmonth, mmddyy10.);

call symput("run_date",run_date);
call symput("beginmonth",beginmonth);
call symput("endingmonth",endingmonth);
call symput("rep_start_date",rep_start_date);
call symput("rep_end_date",rep_end_date);
call symput('today',today);
run;


 

Jeff_DOC
Pyrite | Level 9

Since you both gave me a correct answer I flipped a coin (yes, I'm old enough to still carry coins) and Ballardw won!

 

Thanks for being willing to help!

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
  • 4 replies
  • 355 views
  • 4 likes
  • 3 in conversation