看板 Statistics 關於我們 聯絡資訊
借用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
liton:good job 06/28 00:14
kenshin528:SQL還有min這種指令!! 受教受教@@ 06/28 21:14
liton:min不是很基本的指令嗎@@ excel都有了 06/28 23:55
kenshin528:因為我真的太少用SQL了 活用上不太行 06/29 18:26