Hi all, Could you please help with the following issue. We have dataset with variables x,y,z for subjects 1, 2, 3, etc. We need to add difference - dif(x) between last.observation and 'observation before last'. When simple dif(x) is working it is impossible to apply it for 'last.observation' and 'observation before last'. Does a way exist to sort it out? Please see the code below and output. data multiple;
infile datalines;
input subject 1-2 X 4 Y 6 Z 8;
datalines;
01 1 2 3
01 4 5 6
01 7 8 9
01 8 9 5
02 8 7 6
02 5 4 3
02 2 1 0
03 8 7 9
03 7 5 4
;
run;
proc sort data=multiple;
by subject;
run;
data one;
set multiple;
by subject;
MX=dif(x);
if last.subject then do; LX=dif(x); LY=dif(y); LZ=dif(z); end;
run;
proc print data=one; run;
... View more