2016-11-13 42 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