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!!!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 508 views
  • 3 likes
  • 2 in conversation