## Compute days between dates

Solved
Occasional Contributor
Posts: 14

# Compute days between dates

How do I compute the # of days from date to date.

I have sample data:

Obs.  date1       date2           date3        date4

1       1/1/2010   2/10/2010   3/10/2010  4/5/2010

2       5/3/2011  5/5/2011      5/15/2010

I want output data:

Obs.  date1       date2           date3        date4        daysdif1    daysdif2   daysdif3

1       1/1/2010   2/10/2010   3/10/2010  4/5/2010        40            28             26

2       5/3/2011  5/5/2011      5/15/2010                         2              10

Any help using would be great.

thanks

Accepted Solutions
Solution
‎07-18-2018 03:25 PM
Super User
Posts: 2,078

## Re: Compute days between dates

[ Edited ]
``````data have;
infile cards truncover;
input Obs  (date1       date2           date3        date4) (:mmddyy10.);format date: mmddyy10.;
cards;
1       1/1/2010   2/10/2010   3/10/2010  4/5/2010
2       5/3/2011  5/5/2011      5/15/2011
;

data want;
set have;
array t(*) date:;
array daysdif(3);
do _n_=2 to dim(t);
daysdif(_n_-1)=t(_n_)-t(_n_-1);
end;
run;``````

All Replies
Solution
‎07-18-2018 03:25 PM
Super User
Posts: 2,078

## Re: Compute days between dates

[ Edited ]
``````data have;
infile cards truncover;
input Obs  (date1       date2           date3        date4) (:mmddyy10.);format date: mmddyy10.;
cards;
1       1/1/2010   2/10/2010   3/10/2010  4/5/2010
2       5/3/2011  5/5/2011      5/15/2011
;

data want;
set have;
array t(*) date:;
array daysdif(3);
do _n_=2 to dim(t);
daysdif(_n_-1)=t(_n_)-t(_n_-1);
end;
run;``````
Occasional Contributor
Posts: 14