Here is an obnoxious SQL approach with the undocumented feature: data have; input ID (Enter_Date Exit_Date) (:mmddyy10.) Sex$ Age; format Enter_Date Exit_Date mmddyy10.; cards; 1 1/1/2000 1/1/2002 m 24 1 5/5/2006 5/5/2009 m 30 1 8/8/2011 8/8/2013 m 35 2 2/2/2002 2/2/2005 f 42 2 6/6/2006 6/6/2010 f 46 3 3/3/2003 3/3/2004 m 19 3 4/4/2008 4/4/2012 m 24 ; proc sql; select a.*,b.enter_date-a.exit_date as new_date from (select *, monotonic() as obs from have) a left join (select *, monotonic() as obs from have) b on a.id=b.id and b.obs-a.obs=1 order by id, enter_date; quit; Haikuo
... View more