Re: [程式] 如何在SAS中計算local max & local mini
※ 引述《eminem (阿姆)》之銘言:
: [軟體程式類別]:SAS
: [程式問題]:資料處理
: [軟體熟悉度]:
: 低(1~3個月)
: [問題敘述]:希望在一組股價的時間序列中,找出全部的local max 和 local mini.
: 比方說100 120 115 114 99 150 130 145 100,其中的local max為120,
: 150,145, 而local mini為99,130
: [程式範例]:
: -----------------------------------------------------------------------------
假設target是var1
data localmax(keep=temp2) localmin(keep=temp2);
retain temp1 temp2;
set XXX;
if _n_=1 then temp1=var1;
if _n_=2 then temp2=var1;
if _n_>3 then
do;
if (temp2-temp1)*(var1-temp2)<0 and (temp2-temp1)>0 then
output localmax;
else if (temp2-temp1)*(var1-temp2)<0 and (temp2-temp1)<0 then
output localmin;
temp1=temp2;
temp2=var1;
end;
run;
這裡沒有考慮邊界點以及等號的的定義問題,需要的話再modify一下就行了
當然,coding上或許還有不小的進步空間,上面的版本完全只是土法煉鋼
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.109.40.59
※ 編輯: west1996 來自: 140.109.40.59 (09/17 17:59)
推
09/17 20:02, , 1F
09/17 20:02, 1F
→
09/18 12:37, , 2F
09/18 12:37, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):