data a;
input No cost;
mean=lag(cost)+dif(cost)/2;
if mean= . then mean= cost;
if mean^= . then mean=mean;
if dif(cost)>0 then r1=0;
else r1=1;
if dif2(cost)> dif(cost) then r2=0;
else r2=1;
if r1=1 & r2=0|r1=0 &r2=1 then r=0;
if r1=1 & r2=1|r1=0 & r2=0 then r=1;
drop no y r1 r2;
cards;
1 3767.11
2 4683.89
3 3111.59
4 1111.03
5 4030.38
6 3791.35
7 5361.34
8 1380.84
9 7691.02
10 2079.44
11 3890.88
12 623.45
13 5287.07
14 653
15 4426.4
16 11651.7
17 1569.17
18 4751.24
19 1850.73
20 3267.78
;
proc print;
run;
结果
Obs cost mean r
1 3767.11 3767.11 1
2 4683.89 4225.50 0
3 3111.59 3897.74 0
4 1111.03 2111.31 1
5 4030.38 2570.71 0
6 3791.35 3910.87 0
7 5361.34 4576.35 0
8 1380.84 3371.09 0
9 7691.02 4535.93 0
10 2079.44 4885.23 0
11 3890.88 2985.16 0
12 623.45 2257.17 0
13 5287.07 2955.26 0
14 653.00 2970.04 0
15 4426.40 2539.70 0
16 11651.70 8039.05 1
17 1569.17 6610.44 0
18 4751.24 3160.21 0
19 1850.73 3300.99 0
20 3267.78 2559.26 0
http://www.pinggu.org/bbs/dispbbs.asp?boardid=68&id=271259