Re: [程式] SAS 前後期比較
retain temp flag;
if _n_=1 then do; temp=p; flag=0; t=-1; end;
else if flag=0 then do;
if p=temp then t=-1;
else do;
flag=1;
if p>temp then t=1; else t=0;
temp=p;
end;
end;
else do;
if p>temp then t=1; else t=0;
temp=p;
end;
run;
※ 引述《RequiemInDm (安魂曲)》之銘言:
: : 依照t大寫法
: : Obs P t
: : 1 2 -1
: : 2 2 -1
: : 3 2 -1
: : 4 5 1
: : 5 1 0
: : 6 3 1
: : 7 2 -1
: : 8 3 1
: : 第7項就會被判斷成-1 而不是0 想問一下 有可以選擇從P的哪個資料點開始做判斷
: : 的方法嘛? 感謝回答
: 以下是我自己寫出問題要的答案 (感謝k大跟t大之前推文),
: 只是我在想應該有更簡潔方式寫法才是, 因為用c語言寫判斷式似乎不需要用那麼多!
: retain d 0 n 0;
: lagp = lag(p);
: lag2p = lag2(p);
: if _n_ =1 then d = p;
: if (p = d ) then do;
: if n =0 then t = .;
: else goto pp;
: end;
: pp:
: else do;
: n+1;
: if p > lagp then t=1;
: else if p = lag2p then do;
: if lagp > lag2p then t =1;
: else t =0;
: end;
: else t =0;
: end;
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.36.114.180
推
12/06 22:36, , 1F
12/06 22:36, 1F
推
12/06 22:45, , 2F
12/06 22:45, 2F
→
12/06 22:45, , 3F
12/06 22:45, 3F
→
12/06 23:11, , 4F
12/06 23:11, 4F
→
12/06 23:19, , 5F
12/06 23:19, 5F
討論串 (同標題文章)
完整討論串 (本文為第 4 之 4 篇):
程式
0
1