Desktop productivity for business analysts and programmers

Convert a number to date

Reply
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: 169

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: 7,422

Re: Convert a number to date

data want;
set have;
date = input(put(numdate,8.),yymmdd8.);
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 19,064

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: 11,116

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

 

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 
PROC Star
Posts: 1,146

Re: Convert a number to date

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

 

Tom

New Contributor
Posts: 3

Re: Convert a number to date

Thank you !!

 

Ask a Question
Discussion stats
  • 7 replies
  • 471 views
  • 4 likes
  • 6 in conversation