Re: [程式] sas 找某日期的前一個交易日

看板Statistics作者 (咖啡王子)時間6年前 (2018/03/22 11:14), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《werlinxc (天才小韋)》之銘言: : [軟體程式類別]: SAS : [程式問題]: 偵測參數 : [軟體熟悉度]: 新手 : [問題敘述]: : 板上的大家好,在整理資料時遇到了困難,想尋求協助。 : 資料總共有兩行,第一行是某日期,第二行是日股價,我想找出找出某日期的「前一日( : 必須為交易日)與前一個月」的股價差。 : 有想過用intnx函數,直接拿第一行的某日期減一天,再抓日股價相同的一天。但如果某 : 日期是禮拜一,減一天會是禮拜日,但禮拜日股價不會有資料,應該是要往前推算至最近 : 交易日才對。 : 所以想詢問,如何找出離某日期最近的交易日。 : 謝謝! day means your event day data p means your price data all the date need to be time format proc sql; create table day as select distinct a.stkcd,a.date,max(b.date) as date1 format yymmddn8. from aa.day as a,aa.p as b where a.stkcd=b.stkcd and a.date>b.date and b.close^=. group by a.stkcd,a.date; create table price1day as select a.stkcd,a.date,b.close from day as a,aa.p as b where a.stkcd=b.stkcd and a.date1=b.date; quit; proc sql; create table day as select distinct a.stkcd,a.date,max(b.date) as date1 format yymmddn8. from aa.day as a,aa.p as b where a.stkcd=b.stkcd and intnx('month',a.date,-1,'s')>=b.date and b.close^=. group by a.stkcd,a.date; create table price1month as select a.stkcd,a.date,b.close from day as a,aa.p as b where a.stkcd=b.stkcd and a.date1=b.date; quit; -- -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.72.30.154 ※ 文章網址: https://www.ptt.cc/bbs/Statistics/M.1521688481.A.955.html
文章代碼(AID): #1Qin-XbL (Statistics)
文章代碼(AID): #1Qin-XbL (Statistics)