BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Lapis Lazuli | Level 10

## difference between date in rows by id

Hello I want to make the difference between dates by id

data diff;

set JOINT;
days_between = intck('days',Ann_date,lag(Ann_date));
by number;
run;

this program give this

 Number Ann_date days_between 21 2008-11-12 21 2011-03-29 -867 21 2015-01-21 -1394 21 2016-03-29 -433 24 2003-05-06 4711 24 2016-01-25 -4647 24 2016-05-10 -106 26 2014-08-11 638 46 2009-01-19 2030 53 2008-07-15 188 53 2009-07-27 -377 53 2010-06-11 -319 53 2010-07-16 -35 53 2015-01-15 -1644 53 2015-10-09 -267

I want

 Number Ann_date days_between 21 2008-11-12 21 2011-03-29 -867 21 2015-01-21 -1394 21 2016-03-29 -433 24 2003-05-06 24 2016-01-25 -4647 24 2016-05-10 -106 26 2014-08-11 46 2009-01-19 2030 53 2008-07-15 53 2009-07-27 -377 53 2010-06-11 -319 53 2010-07-16 -35 53 2015-01-15 -1644 53 2015-10-09 -267
1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: difference between date in rows by id

Assuming 46 is a typo as there's only one record.

``````data diff;

set JOINT;
by Number;

days_between = intck('days',Ann_date,lag(Ann_date));

if first.Number then call missing(days_between);

run;``````

@sasphd wrote:

Hello I want to make the difference between dates by id

data diff;

set JOINT;
days_between = intck('days',Ann_date,lag(Ann_date));
by number;
run;

this program give this

 Number Ann_date days_between 21 2008-11-12 21 2011-03-29 -867 21 2015-01-21 -1394 21 2016-03-29 -433 24 2003-05-06 4711 24 2016-01-25 -4647 24 2016-05-10 -106 26 2014-08-11 638 46 2009-01-19 2030 53 2008-07-15 188 53 2009-07-27 -377 53 2010-06-11 -319 53 2010-07-16 -35 53 2015-01-15 -1644 53 2015-10-09 -267

I want

 Number Ann_date days_between 21 2008-11-12 21 2011-03-29 -867 21 2015-01-21 -1394 21 2016-03-29 -433 24 2003-05-06 24 2016-01-25 -4647 24 2016-05-10 -106 26 2014-08-11 46 2009-01-19 2030???? 53 2008-07-15 53 2009-07-27 -377 53 2010-06-11 -319 53 2010-07-16 -35 53 2015-01-15 -1644 53 2015-10-09 -267

2 REPLIES 2
Super User

## Re: difference between date in rows by id

Assuming 46 is a typo as there's only one record.

``````data diff;

set JOINT;
by Number;

days_between = intck('days',Ann_date,lag(Ann_date));

if first.Number then call missing(days_between);

run;``````

@sasphd wrote:

Hello I want to make the difference between dates by id

data diff;

set JOINT;
days_between = intck('days',Ann_date,lag(Ann_date));
by number;
run;

this program give this

 Number Ann_date days_between 21 2008-11-12 21 2011-03-29 -867 21 2015-01-21 -1394 21 2016-03-29 -433 24 2003-05-06 4711 24 2016-01-25 -4647 24 2016-05-10 -106 26 2014-08-11 638 46 2009-01-19 2030 53 2008-07-15 188 53 2009-07-27 -377 53 2010-06-11 -319 53 2010-07-16 -35 53 2015-01-15 -1644 53 2015-10-09 -267

I want

 Number Ann_date days_between 21 2008-11-12 21 2011-03-29 -867 21 2015-01-21 -1394 21 2016-03-29 -433 24 2003-05-06 24 2016-01-25 -4647 24 2016-05-10 -106 26 2014-08-11 46 2009-01-19 2030???? 53 2008-07-15 53 2009-07-27 -377 53 2010-06-11 -319 53 2010-07-16 -35 53 2015-01-15 -1644 53 2015-10-09 -267

Lapis Lazuli | Level 10

## Re: difference between date in rows by id

yes it is a typo

thanks

Discussion stats
• 2 replies
• 1941 views
• 1 like
• 2 in conversation