BookmarkSubscribeRSS Feed
rupalif
Calcite | Level 5

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


2 REPLIES 2
data_null__
Jade | Level 19

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;
rupalif
Calcite | Level 5

It worked! Thank you very much!!!

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
  • 1137 views
  • 3 likes
  • 2 in conversation