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

Solved
Frequent Contributor
Posts: 82

# 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
Posts: 3,852

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

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;

All Replies
Solution
‎01-11-2013 07:20 PM
Posts: 3,852

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

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.