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

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
Reeza
Super User

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

 

View solution in original post

2 REPLIES 2
Reeza
Super User

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

 

sasphd
Lapis Lazuli | Level 10

yes it is a typo

thanks

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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