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 |
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
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
yes it is a typo
thanks
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.