BookmarkSubscribeRSS Feed
gregor1
Quartz | Level 8

I recently ran in to a challenge where I needed to pull the previous month's data from a large list of data with various create dates spanning multiple years.  My solution was:

  1. Create a "Begin of Month" calculated field (I used datepart since I was pulling from a timestamp e.g., INTNX('month',DATEPART( t1.source_actv_create_ts),0)
  2. Then I applied the following filter: t1.BEGIN_OF_MONTH is equal to intnx('month',(intnx('month',today(),0)),-1)

I don't know if there is a better/easier way to do this, but it works regardless if you are within the same year or are spanning years such as wanting December data and today is January.  I anyone has a better method, I would be interested in learning.

2 REPLIES 2
CarmineVerrell
SAS Employee

FYI  Unfortunately, i can't provide a detailed response. Next time please provide us with sample data and code, so we can provide a detailed example.

 

Thanks for the question, as you stated you were able to get it to work with INTNX. So, I would not have any other suggestions for you.

 

You provided one line of code, so even if we would use other functions to get the same results it won’t make any difference in your program. Your solution seems good and it's working so I would just leave it as is.

 

If you are concerned with improving the program code and analyzing how you can improve the run time length. I would highly recommend taking more Advanced SAS training. In this case, I would suggest a SAS Programming 3 course.

gregor1
Quartz | Level 8

Good to know - thanks Carmine!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Discussion stats
  • 2 replies
  • 1108 views
  • 0 likes
  • 2 in conversation