You need to do a "look-ahead":
data have;
input ID date :mmddyy10. cumulative_reading;
format date yymmddd10.;
datalines;
1 10/1/19 100
1 10/2/19 150
1 10/3/19 200
2 10/1/19 100
2 10/2/19 500
2 10/3/19 900
;
options mergenoby=nowarn;
data want;
merge
have
have (
firstobs=2
keep=id cumulative_reading
rename=(id=nextid cumulative_reading=nextval)
)
;
if id = nextid then daily_usage = nextval - cumulative_reading;
drop nextid nextval;
run;
proc print data=want noobs;
run;
Result:
cumulative_ daily_
ID date reading usage
1 2019-10-01 100 50
1 2019-10-02 150 50
1 2019-10-03 200 .
2 2019-10-01 100 400
2 2019-10-02 500 400
2 2019-10-03 900 .
... View more