2016-11-13 41 views
0

我在一些示例數據上使用哈希連接來連接較大的一個小表。在這個例子中,'_1080544_27_08_2016'是較大的表,'_2015_2016_playerlistlookup'是較小的一個。這裏是我的代碼:哈希連接不按要求運行

data both(drop=rc); 
declare Hash Plan 
(dataset: 'work._2015_2016_playerlistlookup');        /* declare the name Plan for hash */ 
rc = plan.DefineKey ('Player_ID');           /* identify fields to use as keys */ 
rc = plan.DefineData ('Player_Full_Name', 
'Player_First_Name', 'Player_Last_Name', 
'Player_ID2');                 /* identify fields to use as data */ 
rc = plan.DefineDone();             /* complete hash table definition */ 
do until (eof1) ;               /* loop to read records from _1080544_27_08_2016 */ 
set _1080544_27_08_2016 end = eof1; 
rc = plan.add();               /* add each record to the hash table */ 
end; 
do until (eof2) ;               /* loop to read records from _2015_2016_playerlistlookup */ 
set _2015_2016_playerlistlookup end = eof2; 
call missing(Player_Full_Name, 
Player_First_Name, Player_Last_Name);          /* initialize the variable we intend to fill */ 
rc = plan.find();               /* lookup each plan_id in hash Plan */ 
output;                 /* write record to Both */ 
end; 
stop; 
run; 

這是產生一個與較小的查找表具有相同行數的表。我想查看一個表的大小是否與通過主鍵連接的查找表中的更大字段相同。

較大的表具有重複的主鍵。也就是說,主鍵不是唯一的(例如根據行號)。

有人可以告訴我,我需要修改代碼嗎?

感謝

回答

2

您正在加載兩個數據集中到你的哈希對象 - 小個的,當你把它聲明,再大的一個,以及在你第一次做循環。這對我來說沒有意義,除非您的查詢值已經爲大數據集中的某些行(但不是所有行)填充,並且您試圖在行之間執行它們。

然後循環查找數據集併爲該數據集的每一行生成1個輸出行。

現在還不清楚你在這裏試圖做什麼,因爲這不是散列對象的標準用例。

這是我最好的猜測 - 如果這不是你想要做的,請發佈樣本輸入和預期的輸出數據集。

data want; 
set _1080544_27_08_2016; 
if 0 then set _2015_2016_playerlistlookup; 
if _n_ = 1 then do; 
    declare Hash Plan(dataset: 'work._2015_2016_playerlistlookup');        
    rc = plan.DefineKey ('Player_ID'); 
    rc = plan.DefineData ('Player_Full_Name', 'Player_First_Name', 'Player_Last_Name', 'Player_ID2');                 
    rc = plan.DefineDone(); 
end; 
call missing(Player_Full_Name, Player_First_Name, Player_Last_Name); 
rc = plan.find(); 
drop rc; 
run; 
+0

嗨,謝謝你的回覆。你能否給我這樣的例子代碼,因爲我不知道你在說什麼。謝謝。 – gdogg371

+0

我猜測你想要做什麼 - 如果這不是你想要的,請發佈一些示例數據。 – user667489