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
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.
data want;
set have;
date = input(put(numdate,8.),yymmdd8.);
run;
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.
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.
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_DT | put(t1.BOOKING_DT,8.) | input((put(t1.BOOKING_DT,8.)),yymmd8.) | intnx('month',(input((put(t1.BOOKING_DT,8.)),yymmd8.)),-1,'same') |
20140717 | 20140717 | 20140717 | |
20140808 | 20140808 | 20140808 | |
20140904 | 20140904 | 20140904 | |
20140910 | 20140910 | 20140910 | |
20140918 | 20140918 | 20140918 | |
20141013 | 20141013 | 20141013 | |
20141107 | 20141107 | 20141107 |
You're missing a letter in the format name. It's yymmdd8. not yymmd8.
Tom
Thank you !!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.