Desktop productivity for business analysts and programmers

Convert a number to date

New Contributor
Posts: 3

Convert a number to date

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

Regular Contributor
Posts: 216

Re: Convert a number to date

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.

Super User
Posts: 10,610

Re: Convert a number to date

data want;
set have;
date = input(put(numdate,8.),yymmdd8.);
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 24,026

Re: Convert a number to date

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. 



Super User
Posts: 13,942

Re: Convert a number to date

First thing when looking at manipulating dates is to start with a SAS date valued variable. @KurtBremser 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.

New Contributor
Posts: 3

Re: Convert a number to date

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 !!


Posts: 1,334

Re: Convert a number to date

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



New Contributor
Posts: 3

Re: Convert a number to date

Thank you !!


Ask a Question
Discussion stats
  • 7 replies
  • 6 in conversation