addictedtome 发表于 2010-5-28 11:03 
数据是这样的:
name date egg change
1 3-1 2
1 3-2 3
1 3-3 5
1 3-4 1
2 3-1 1
2 3-2 3
3 3-1 3
3 3-2 4
3 3-3 2
4 3-1 1
4 3-2 1
5 3-1 5
5 3-1 4
5 3-2 7
5 3-3 3
需要求每个name,date (t)的egg的值 与 date (t-1)的egg的值的差额。例如name 1, date 3-2时的change=3-2=1,
求高手赐教!
If I understand it correct, the change is defined within the name block. Here is a sample problem.
data a;
input name date $ egg;
datalines;
1 3-1 2
1 3-2 3
1 3-3 5
1 3-4 1
2 3-1 1
2 3-2 3
3 3-1 3
3 3-2 4
3 3-3 2
4 3-1 1
4 3-2 1
5 3-1 5
5 3-1 4
5 3-2 7
5 3-3 3
;
data b;
set a;
by name;
change=dif(egg);
if first.name then change=.;
run;
proc print; run;