data test2 (drop=a b);
set test1;
nm2=n-2; *n-2;
nm1=n-1;
nn=n;
np1=n+1;
np2=n+2;
if b ge 10;
run;
data test3;
set test2;
recordind=_n_;
if nm2 then do; n=nm2; output; end;
if nm1 then do; n=nm1; output; end;
if nn then do; n=nn; output;end;
if np1 then do; n=np1;output;end;
if np2 then do; n=np2;output;end;
run;
data test4 (keep=a b recordind);
merge test1 test3 (in =c);
by n;
if c;
run;
data test5 (keep=var1-var5);
set test4;
by recordind;
retain var1 var2 var3 var4 var5;
if first.recordind then m=0;
m+1;
if m=1 then var1=b;
if m=2 then var2=b;
if m=3 then var3=b;
if m=4 then var4=b;
if m=5 then var5=b;
if last.recordind;
run;作者: shiyiming 时间: 2004-10-25 10:26 标题: re 确实比较麻烦,其实并不太难,应该有更好的办法没时间想了(用宏会优化很多),用了个最直接的,可以做的。
data test2 (drop=a b);
set test1;
nm2=n-2; *n-2;
nm1=n-1;
nn=n;
np1=n+1;
np2=n+2;
if b ge 10;
run;
data test3;
set test2;
recordind=_n_;
if nm2 then do; n=nm2; output; end;
if nm1 then do; n=nm1; output; end;
if nn then do; n=nn; output;end;
if np1 then do; n=np1;output;end;
if np2 then do; n=np2;output;end;
run;
data test4 (keep=a b recordind);
merge test1 test3 (in =c);
by n;
if c;
run;
data test5 (keep=var1-var5);
set test4;
by recordind;
retain var1 var2 var3 var4 var5;
if first.recordind then m=0;
m+1;
if m=1 then var1=b;
if m=2 then var2=b;
if m=3 then var3=b;
if m=4 then var4=b;
if m=5 then var5=b;
if last.recordind;
run;作者: shiyiming 时间: 2004-10-25 10:34 标题: 能否把结果的显示形式写出来 ai-1 是指下标减一,还是指ai的值减一作者: shiyiming 时间: 2004-10-25 10:49 标题: :):):) 是下标减1!!!!作者: shiyiming 时间: 2004-10-25 11:10 标题: 辛苦大家了!:) 编出这么长程序的laolan哦,目的还是达到了,但是当我输入真正的数据之后(如下是数据的一部分),test2里面的结果却还是整数,不知道为何?另,有无更简单些的程序,便于修改,因为我要的数据其实是ai-20至ai+30,共51个数据一行!再另,好像test3-5的数据没什么用哦?