看板 Statistics 關於我們 聯絡資訊
------------------------------------------------------------------------ [軟體程式類別]: SAS [程式問題]: 目前想利用sql count(*)計算數值出現次數,但我只會分成很多次語法寫, 第一次跑可以,但第二次計算的時候就出現錯誤訊息, 不知各位有沒有更好的方法,或我語法那邊錯誤,謝謝。 [軟體熟悉度]: 低(1~3個月) [問題敘述]: 原本資料有id 與 case_type兩變項,想計算case_type欄位數值出現次數, 新創欄位type1,type2,type3。 原本資料想要變為: ID case_type ---> ID case_type type1 type2 type3 a 1 a 1 2 0 0 a 1 a 1 2 0 0 b 1 b 1 1 1 1 b 2 b 2 1 1 1 b 3 b 3 1 1 1 我的語法: 第一次計算type1的次數 proc sql; create table A as select id,case_type, count(*)type1 from a where case_type in(1) group by id;quit; 第二次計算type2的次數 proc sql; create table A as select id,case_type, count(*)type2 from A where case_type in(2) group by id;quit; 第一次算還會出現type1欄位,第二次就說明錯誤,不曉得我是哪邊錯了呢? 謝謝各位解答!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.80.147.129
MmmRrrrX:跟SQL不算熟,不過group by 只放 id ,照理講 select 裡 09/09 23:53
MmmRrrrX:不應該出現 case_type 09/09 23:53
JeanYCY:第一次下了where,data A裡就不再包含case_type=2的資料 09/10 10:28
JeanYCY:應該說data A中只留下case_type=1的資料... 09/10 10:29
MmmRrrrX:或者是create table A 將原始資料的 a 取代掉了 (?) 09/10 23:25