Re: [程式] SAS yyyymmdd資料抓每月最後一日資料

看板Statistics作者 (咖啡王子)時間9年前 (2014/10/01 12:34), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
proc sql; create table time as select date, year(date) as y, month(date) as m from yourdata; create table month as select y,m, max(date) as date from time group by y,m; create table monthdata as select * from yourdata where date in (select date from month); quit; 以上把思考流程寫的很清楚 但是一點不會很簡潔就是了 沒開sas可能會寫錯 你自己研究吧 ※ 引述《e181280 (小波)》之銘言: : [軟體程式類別]: : SAS : [程式問題]: : 資料處理 : [軟體熟悉度]: : 低(1~3個月) : [問題敘述]: : 抓取每月最後一天的資料 : symbol name date prc vol ind ret : 1. 1111 aaa 2010-01-01 b1 c1 d1 0.ab1 : 2. 1111 aaa 2010-01-02 b2 c2 d2 0.ab2 : ... : 31. 1111 aaa 2010-01-31 b31 c31 d31 0.ab31 : 32. 1111 aaa 2010-02-01 b32 c32 d32 0.ab32 : 59. 1111 aaa 2010-02-28 b59 c59 d59 0.ab59 : 60. 1111 aaa 2010-03-01 b60 c60 d60 0.ab60 : ... : 90. 1111 eee 2010-03-31 b90 c90 d90 0.ef90 : 91. 1111 eee 2010-01-01 f1 g1 h1 0.ef1 : 121. 1111 eee 2010-01-31 f31 g31 h31 0.ef31 : 122. 1111 eee 2010-02-01 f32 g32 h32 0.ef32 : ... : 149. 1111 eee 2010-02-28 f59 g59 h59 0.ef59 : 150. 1111 eee 2010-03-01 f60 g60 h60 0.ef60 : ... : 180. 1111 eee 2010-03-31 f90 g90 h90 0.ef90 : [程式範例]: : 原本是想說用 day = day(date) 抓取 day 的值出來再用 last.day : 抓取每月最後一天的資料,但是會出現 last.day 沒有 : 雖然目前用以下方法有做出我想要的 : data a_a_last ; : Set HW_ret ; by symbol date ; : day = day(date); : month = month(date); : year = year (date); : run ; : proc sort data = a_a_last out = last ; by symbol month year descending day ; : quit ; : data a_a_last ; : Set last ; by symbol month year ; : If day > lag(day) or lag(day) = . then output; : Drop day month year ; : run ; : 但是想問說可不可以用 last.day 或其他更簡潔方法做出 -- -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 122.228.131.72 ※ 文章網址: http://www.ptt.cc/bbs/Statistics/M.1412138053.A.153.html
文章代碼(AID): #1KAuH55J (Statistics)
文章代碼(AID): #1KAuH55J (Statistics)