DATA Step, Macro, Functions and more

How to identify prev month's year

Accepted Solution Solved
Reply
Contributor
Posts: 55
Accepted Solution

How to identify prev month's year

I want a sas logic to identify previous month's year. For example, 1. if current month year JAN 2016 then I need to retrieve 2015 2. if current month year FEB 2016 then I need to retrieve 2016

Accepted Solutions
Solution
‎09-02-2016 09:57 AM
Super User
Posts: 19,864

Re: How to identify prev month's year

Posted in reply to jayakumarmm

Is your variable a SAS date, ie numeric with a date format?

 

If so this should work, I split it up for clarity but you can nest your functions. 

 

Prev_Month = INTNX('month', date_var, -1, 'B');
Prev_Year = year(Prev_Month);

View solution in original post


All Replies
Solution
‎09-02-2016 09:57 AM
Super User
Posts: 19,864

Re: How to identify prev month's year

Posted in reply to jayakumarmm

Is your variable a SAS date, ie numeric with a date format?

 

If so this should work, I split it up for clarity but you can nest your functions. 

 

Prev_Month = INTNX('month', date_var, -1, 'B');
Prev_Year = year(Prev_Month);
Occasional Contributor
Posts: 8

Re: How to identify prev month's year

Posted in reply to jayakumarmm

Using some of Reeza's code but adding 'Today' function:

 

Prev_months_year = year(INTNX('month', today(), -1, 'B'));

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 233 views
  • 1 like
  • 3 in conversation