BookmarkSubscribeRSS Feed
BCNAV
Quartz | Level 8

I have the following filter:

 

WHERE t1.flightdate >= intnx('Month',today(),-&months_back)

 

so if &months_back is 3, I will get data from all of June, July, and August of this year.....but it will also include September. I do not want September...I only want the last number of FULL months as identified with the macro variable &months_back. What filter can I add to get rid of the partial month dates?

3 REPLIES 3
Reeza
Super User
WHERE t1.flightdate >= intnx('Month',today(),-&months_back) and t1.flightdate < intnx('month', today(), 0, 'b');

Same idea, use INTNX() to get current months first day (interval = 0, aligment = b) and use BETWEEN or < for the date. 

 


@BCNAV wrote:

I have the following filter:

 

WHERE t1.flightdate >= intnx('Month',today(),-&months_back)

 

so if &months_back is 3, I will get data from all of June, July, and August of this year.....but it will also include September. I do not want September...I only want the last number of FULL months as identified with the macro variable &months_back. What filter can I add to get rid of the partial month dates?


 

ballardw
Super User

SAS supports structures like

 

Where value1 < value2 < value3

 

So add the other constraint

 

WHERE  somevalue > t1.flightdate >= intnx('Month',today(),-&months_back)

 

perhaps

 

where intx('month',today(),0,'B') > t1.flightdate >= intnx('Month',today(),-&months_back)

if you only want dates prior to the beginning of the current month.

 

 

novinosrin
Tourmaline | Level 20

where intnx('Month',today(),-3)<=date<=intnx('Month',today(),-1,'e');

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 985 views
  • 0 likes
  • 4 in conversation