Calculating day span across longitudinal data

Reply
New Contributor
Posts: 2

Calculating day span across longitudinal data

Hi,I am trying to calculate difference between two dates from two different rows. I have unique memberid, effective date and end date variables. for some members there are multiple rows. I want to calculate difference between End date and effective date from next row for that member.

thanks


Respected Advisor
Posts: 3,775

Re: Calculating day span across longitudinal data

Something like this?

data long;
   input id s e;
   informat s e date9.;
  
format s e date9.;
  
cards;
1 10DEC2012 10FEB2013
1 17DEC2013 19FEB2014
2 10NOV2012 10FEB2013
2 10MAR2013 12APR2013
2 17DEC2013 19FEB2014
;;;;
   run;
data longnext;
   set long end=eof;
   by id;
   if not eof then set long(firstobs=2 keep=s rename=s=nxs);
   if not last.id then dif = nxs-e;
   run;
proc print;
  
run;
New Contributor
Posts: 2

Re: Calculating day span across longitudinal data

It worked! Thank you very much!!!

Ask a Question
Discussion stats
  • 2 replies
  • 163 views
  • 3 likes
  • 2 in conversation