I need help getting a difference between subsequent values on a list

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 82
Accepted Solution

I need help getting a difference between subsequent values on a list

So I need to see how many days have passed between observations.

So :

Person Date

A 1/1/12

A  1/5/12

A  1/7/12

B 4/5/12

B 4/9/12

B and so on

B

B

C

C

Basically, I want a column to the right that says X days have passed since last instance. I am thinking an array, but I am horrible at arrays.


Accepted Solutions
Solution
‎01-11-2013 07:20 PM
Respected Advisor
Posts: 3,799

Re: I need help getting a difference between subsequent values on a list

DIF function sounds about right.

data dif;
   input id:$1. date :mmddyy.;
  
format date date.;
  
cards;
A 1/1/12
A  1/5/12
A  1/7/12
B 4/5/12
B 4/9/12
;;;;
   run;
data dif2;
   set dif;
   by id;
   dif = dif(date);
  
if first.id then dif=.F;
  
run;

View solution in original post


All Replies
Solution
‎01-11-2013 07:20 PM
Respected Advisor
Posts: 3,799

Re: I need help getting a difference between subsequent values on a list

DIF function sounds about right.

data dif;
   input id:$1. date :mmddyy.;
  
format date date.;
  
cards;
A 1/1/12
A  1/5/12
A  1/7/12
B 4/5/12
B 4/9/12
;;;;
   run;
data dif2;
   set dif;
   by id;
   dif = dif(date);
  
if first.id then dif=.F;
  
run;
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 143 views
  • 0 likes
  • 2 in conversation