BookmarkSubscribeRSS Feed
Anirudh1
Fluorite | Level 6

Hello, I am trying to do a report with Month over month% change. Our date field is a numeric field i.e for example has value 20160501. I need to get priormonth same day and compare counts . I am trying to do this in sas enterprise guide. What is the function I should use to get priormonth day value out of this field? Any help is much appreciated

7 REPLIES 7
paulkaefer
Lapis Lazuli | Level 10

Use the INTNX function.

 

For example:

 

intnx('month', yourVariable, -1, 'same');

will return the same day in the previous month (-1)

Use 'b' or 'e' to return the beginning or end day of the previous month, respectively.

 

More information and examples.

Reeza
Super User

I'm assuming you're asking how to find the record that is a year before, not just the date. 

 

You need to provide your data structure, what you want as output and ideally, if you're using the GUI in EG or coding. 

Please post data as text, NOT as an image. 

 

 

ballardw
Super User

First thing when looking at manipulating dates is to start with a SAS date valued variable. @Kurt_Bremser shows how to convert your number to a SAS date value.

Then you can use a number of SAS functions to either increment a date, INTNX or examine the different number of time periods between two dates (or time or datetimes) with INTCK.

 

You would likely want to look a a new date of a given interval.

Priormonth = INTNX('month',date,-1,'same');

That says to create a new date value that is one month before the value of date for the same day of the month.

 

How to compare counts would require much more knowledge about the structure of your current data set and how you are counting. You might be better off posting some example input data and the desired result.

Anirudh1
Fluorite | Level 6

Thank you all for your responses !!

 

I am using GUI in the SAS EG. If I can get the prior month date value then I know how to get the record and do the comparsion...Here is what I have. I have a booking date which is a number and I think the input function posted by KurtBremser I converted to date and the next step was to get prior month same day but I am getting a blank...I am not sure what I am doing wrong.

 

Thank you for helping me out !!

 

BOOKING_DTput(t1.BOOKING_DT,8.)input((put(t1.BOOKING_DT,8.)),yymmd8.)intnx('month',(input((put(t1.BOOKING_DT,8.)),yymmd8.)),-1,'same')
201407172014071720140717 
201408082014080820140808 
201409042014090420140904 
201409102014091020140910 
201409182014091820140918 
201410132014101320141013 
201411072014110720141107 
TomKari
Onyx | Level 15

You're missing a letter in the format name. It's yymmdd8. not yymmd8.

 

Tom

Anirudh1
Fluorite | Level 6

Thank you !!

 

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 7 replies
  • 3061 views
  • 4 likes
  • 6 in conversation