Re: [問題] SAS中使用SQL與MERGE合併資料

看板Statistics作者 (........)時間12年前 (2011/11/16 21:46), 編輯推噓3(300)
留言3則, 2人參與, 最新討論串2/3 (看更多)
※ 引述《liton (歐吉桑留學生)》之銘言: : 以SQL寫的話 產出會符合我的需求 : 但有辦法用MERGE PROCESS寫嗎??(因為一些緣故 必須用MERGE寫) 如同前面推文 A 大給了 point 的提示, 以下這樣寫應該可以達到多對多合併的結果: data B_idx; keep Common B_from B_to; retain B_from; set B (keep=Common); by Common; if first.Common then B_from = _N_; if last.Common then do; B_to = _N_; output; end; run; data AB (keep=Common Column_A Column_B); merge A B_idx; by Common; do i = B_from to B_to; set B point=i; output; end; run; 我覺得還是用 SQL 去寫比較簡單也比較有效率一點~! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.240.33.35 ※ 編輯: KnightX 來自: 111.240.33.35 (11/16 21:48)

11/16 22:52, , 1F
cartesian product 這麼複雜@@
11/16 22:52, 1F

11/17 09:23, , 2F
如果Common不是全都是1 例如是1 ,2 好像就沒有product
11/17 09:23, 2F

11/17 10:08, , 3F
我說的是Common 如果不是都是M,而是F,M 結果還是兩筆
11/17 10:08, 3F
文章代碼(AID): #1Emxx6H6 (Statistics)
文章代碼(AID): #1Emxx6H6 (Statistics)