BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ogrigny
Fluorite | Level 6

Hi,

I need to automatically calculate a date in macro variable that corresponds to the 2nd of the following month (i.e. if the code runs in November, the desired date will be 02dec2022).

I use this code to get the 2nd of the current month:

 

%let wanted_day=2;
%put &wanted_day;

%let wanted_date=%sysfunc(MDY(%sysfunc(month(%sysfunc(today()))),%sysevalf(&wanted_day.),%sysfunc(year(%sysfunc(today())))),date9.);
%put &wanted_date;

Can I change it to shift the month or do I need another approach?

Thanks for your help.

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

First, get this to work in a DATA step, much simpler with fewer %SYSFUNC calls (actually 0 %SYSFUNC calls) and fewer parentheses to possibly mismatch. Then you can use CALL SYMPUTX to create the macro variable.

 

%let wanted_day=2;
data _null_;
    date=today();
    day_of_next_month=intnx('month',date,1,'b')+(&wanted_day-1);
    call symputx('wanted_date',day_of_next_month);
run;
%put &=wanted_date;
%put %sysfunc(putn(&wanted_date,date9.));

 

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

First, get this to work in a DATA step, much simpler with fewer %SYSFUNC calls (actually 0 %SYSFUNC calls) and fewer parentheses to possibly mismatch. Then you can use CALL SYMPUTX to create the macro variable.

 

%let wanted_day=2;
data _null_;
    date=today();
    day_of_next_month=intnx('month',date,1,'b')+(&wanted_day-1);
    call symputx('wanted_date',day_of_next_month);
run;
%put &=wanted_date;
%put %sysfunc(putn(&wanted_date,date9.));

 

--
Paige Miller
ogrigny
Fluorite | Level 6

thanks ! super helpful now I see the logic.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1562 views
  • 1 like
  • 2 in conversation