作者KnightX (........)
看板Statistics
標題Re: [問題] SAS中使用SQL與MERGE合併資料
時間Wed Nov 16 21:46:42 2011
※ 引述《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)
推 liton: cartesian product 這麼複雜@@ 11/16 22:52
推 imaltar:如果Common不是全都是1 例如是1 ,2 好像就沒有product 11/17 09:23
推 imaltar:我說的是Common 如果不是都是M,而是F,M 結果還是兩筆 11/17 10:08