Date: Thu, 24 Feb 2005 15:41:08 -0500
Reply-To: Krishnan Viswanathan <krisviswanathan@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Krishnan Viswanathan <krisviswanathan@GMAIL.COM>
Subject: Calculate row differences
Hi
I have an dataset like this :
hhid vehid day startbalance price
100 1 1 10 1
100 1 2 10 2
100 1 3 10 3
100 1 4 10 2
100 2 1 15 3
100 2 2 15 1
100 2 3 15 2
100 2 4 15 1
101 1 1 20 2
101 1 2 20 3
101 1 3 20 2
101 1 4 20 1
101 2 1 25 2
101 2 2 25 3
101 2 3 25 2
101 2 4 25 2
101 2 5 25 4
For each HHID & VEHID combination, i want to calculate the difference
between the ending balance (startbalance - price) for row 1 and new start
balance ending balance - price for each subsequent row. The output I desire
is as follows :
hhid vehid day startbalance price endbalance
100 1 1 10 1 9
100 1 2 9 2 7
100 1 3 7 3 4
100 1 4 4 2 2
100 2 1 15 3 12
100 2 2 12 1 11
100 2 3 11 2 9
100 2 4 9 1 8
101 1 1 20 2 18
101 1 2 18 3 15
101 1 3 15 2 13
101 1 4 13 1 12
101 2 1 25 2 23
101 2 2 23 3 20
101 2 3 20 2 18
101 2 4 18 2 16
101 2 5 16 4 12
Any help would be appreciated.
Thanks,
Krishnan