Re: [程式] SAS資料計算

看板Statistics作者 (咖啡王子)時間15年前 (2010/06/27 23:35), 編輯推噓2(202)
留言4則, 2人參與, 最新討論串7/7 (看更多)
借用liton的語法 我把他改出來了 稍微修正就可以了 data a; set a; retain o 0; if response^=lag(response) then o=o+1; run; proc sql; create table final as select date,response, (case when response^=1 and min(date)^=max(date) then max(date)-min(date)+1 else . end) as days from a group by o ; quit; ※ 引述《liton (歐吉桑留學生)》之銘言: : 我程式的就兩段 : 借用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: 134.208.29.183

06/28 00:14, , 1F
good job
06/28 00:14, 1F

06/28 21:14, , 2F
SQL還有min這種指令!! 受教受教@@
06/28 21:14, 2F

06/28 23:55, , 3F
min不是很基本的指令嗎@@ excel都有了
06/28 23:55, 3F

06/29 18:26, , 4F
因為我真的太少用SQL了 活用上不太行
06/29 18:26, 4F
文章代碼(AID): #1C9s-cia (Statistics)
討論串 (同標題文章)
文章代碼(AID): #1C9s-cia (Statistics)