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

Hi

I am using a Date prompt to get a month and year (the macro has the values in DDMMMYY format eg: 01JAN2022).

Can someone help me to find a way to obtain the next month and the previous month?

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Here is one way that is easy to follow:

%let MyDate = 01Jan2022;

data _null_;
 Next_Month = intnx('MONTH', "&MyDate"d, 1, 'BEGINNING');
 Last_Month = intnx('MONTH', "&MyDate"d, -1, 'BEGINNING');
 format Next_Month Last_Month date9.;
 call symputx('Next_Month',  put(Next_Month,date9.)); 
 call symputx('Last_Month',  put(Last_Month,date9.)); 
 put _all_;
run;

%put Next_Month = &Next_Month;
%put Last_Month = &Last_Month;

View solution in original post

2 REPLIES 2
SASKiwi
PROC Star

Here is one way that is easy to follow:

%let MyDate = 01Jan2022;

data _null_;
 Next_Month = intnx('MONTH', "&MyDate"d, 1, 'BEGINNING');
 Last_Month = intnx('MONTH', "&MyDate"d, -1, 'BEGINNING');
 format Next_Month Last_Month date9.;
 call symputx('Next_Month',  put(Next_Month,date9.)); 
 call symputx('Last_Month',  put(Last_Month,date9.)); 
 put _all_;
run;

%put Next_Month = &Next_Month;
%put Last_Month = &Last_Month;
madara155
Obsidian | Level 7

Thank you very much! It worked 🙂

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 508 views
  • 2 likes
  • 2 in conversation