Re: [程式] SAS資料計算

看板Statistics作者 (歐吉桑留學生)時間14年前 (2010/06/27 16:12), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串6/7 (看更多)
我程式的就兩段 借用t大的資料 ※ 引述《tew (咖啡王子)》之銘言: : data a; : input date date10. response; : format date date9. ; : cards; : 09AUG07 1 : 23AUG07 1 : 06SEP07 2 : 20SEP07 2 : 05OCT07 3 : 16OCT07 3 : 30OCT07 3 : 29NOV07 1 : 01JAN08 2 : 10JAN08 3 : 19JAN08 3 : 30JAN08 4 : 10JUN08 4 : ; : run; data c; set a; retain initial_date group 0; format initial_date date9. ; if response ne 1 and response ne lag(response) then initial_date=date; if response ne lag(response) then group+1; tmp_days= date-initial_date+1 ; run; proc sql; create table result as select date,response, (case when response eq 1 then 0 else max(tmp_days) end) as days from C group by group ; quit; -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.167.174.54

06/27 16:12, , 1F
和t大的差異在01JAN2008這筆資料
06/27 16:12, 1F

06/27 17:39, , 2F
受教了~~~
06/27 17:39, 2F
文章代碼(AID): #1C9mVPPC (Statistics)
討論串 (同標題文章)
文章代碼(AID): #1C9mVPPC (Statistics)