Solved
Contributor
Posts: 71

# 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.

Accepted Solutions
Solution
‎11-21-2016 11:15 PM
Super User
Posts: 6,628

## 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.);

All Replies
Solution
‎11-21-2016 11:15 PM
Super User
Posts: 6,628

## 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: 23,249

## 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.