DATA Step, Macro, Functions and more

date difference from particular date and output in number of days

Accepted Solution Solved
Reply
Contributor
Posts: 71
Accepted Solution

date difference from particular date and output in number of days

Hello Everyone,

 

I am trying to find the difference in two dates in number of days. I have dates in numeric format as follows:

20150218
20150216
20150219
20150220
20150315
20150317
20150319
20150320
20150321
20150322

 

Now I want the difference of theses dates from 20161001 in number of days.

Thanks in advance !


Accepted Solutions
Solution
‎11-21-2016 11:15 PM
Super User
Posts: 5,082

Re: date difference from particular date and output in number of days

SAS has better ways to store dates, instead of using an 8-digit number.  If you used SAS's usual methods, you could just code:

 

difference = '01oct2016'd - mydate;

 

Given the data you already have, you will need a more complex formula:

 

difference = '01oct2016'd - input(put(mydate, 8.), yymmdd8.);

View solution in original post


All Replies
Solution
‎11-21-2016 11:15 PM
Super User
Posts: 5,082

Re: date difference from particular date and output in number of days

SAS has better ways to store dates, instead of using an 8-digit number.  If you used SAS's usual methods, you could just code:

 

difference = '01oct2016'd - mydate;

 

Given the data you already have, you will need a more complex formula:

 

difference = '01oct2016'd - input(put(mydate, 8.), yymmdd8.);

Contributor
Posts: 71

Re: date difference from particular date and output in number of days

Thanks.... The input was not in my hand.. it is CSV file, i received...
Super User
Posts: 17,829

Re: date difference from particular date and output in number of days

How did you import the CSV?

That should be under your control and best practice would be to read it in as a date. 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 169 views
  • 0 likes
  • 3 in conversation