作者west1996 (焦了六年变脆了)
看板Statistics
标题Re: [程式] 如何在SAS中计算local max & local mini
时间Thu Sep 17 17:58:03 2009
※ 引述《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)
1F:推 eminem:先谢过~(仍在研读中) 09/17 20:02
2F:→ west1996:上面有错if _n_>3要改成_n_>=3 09/18 12:37