can some one resolve the issue there:
data want;
set have;
by mac;
if first.mac then do; DayDif=0; KmDif=0; end;
else do;
DayDif = Date - lag(Date); /* calculate the difference between two dates */
KmDiff = Kms - lag(Kms);
end;
run;
And what I got result is as (0 in first line but . in second):
Mac Date Kms DayDif KmDif
SP0001 10DEC07 1885462.00000 0 0
SP0001 12DEC07 1885462.00000 . .
SP0001 30APR09 1885462.00000 505 0
SP0001 15JUL09 1886577.00000 76 1115
SP0001 16JUL09 1887667.00000 1 1090
SP0001 17JUL09 1889181.00000 1 1514
SP0001 17JUL09 1888825.00000 0 -356
.
.
(here When machine changed, lag is taken as t - (t-2) and not as t - (t-1) ) why???? something wrong in the code ??
Machine Date Kms DayDif KmDif
SP0001 01OCT14 2898108.00000 1 1059
SP0001 02OCT14 2899148.00000 1 1040
HP0001 03OCT14 2900334.00000 1 1186
HP0002 17JAN08 926384.00000 0 0
HP0002 18JAN08 926384.00000 -2450 -1973950
HP0002 28APR09 1237332.00000 466 310948
HP0002 29APR09 1238599.00000 1 1267