Sas 哈希联接的行为不符合要求
我在一些示例数据上使用散列联接,将一个小表联接到一个大表上。在本例中,“_1080544_27_08_2016”是较大的表格,“_2015_2016_playerlistlookup”是较小的表格。这是我的密码:Sas 哈希联接的行为不符合要求,sas,hashtable,Sas,Hashtable,我在一些示例数据上使用散列联接,将一个小表联接到一个大表上。在本例中,“_1080544_27_08_2016”是较大的表格,“_2015_2016_playerlistlookup”是较小的表格。这是我的密码: data both(drop=rc); declare Hash Plan (dataset: 'work._2015_2016_playerlistlookup'); /* declare the name Plan fo
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;
这将生成一个与较小的查找表具有相同行数的表。我希望看到的是,如果一个表的大小与较大的表相同,并且通过主键连接了查找表中的其他字段
较大的表具有重复的主键。也就是说主键不是唯一的(例如基于行号)
有人能告诉我需要修改的代码吗
谢谢您正在将这两个数据集加载到您的哈希对象中—声明时是小数据集,然后在第一个do循环中也是大数据集。这对我来说毫无意义,除非您已经为大型数据集中的某些行(而不是所有行)填充了查找值,并且您正试图在行之间传递它们 然后在查找数据集中循环,并为该数据集中的每一行生成一个输出行 现在还不清楚您在这里到底想做什么,因为这不是散列对象的标准用例 这里是我最好的猜测——如果这不是您想要做的,请发布示例输入和预期输出数据集
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;
您正在将这两个数据集加载到您的哈希对象中——声明时是小数据集,然后在第一个do循环中也是大数据集。这对我来说毫无意义,除非您已经为大型数据集中的某些行(而不是所有行)填充了查找值,并且您正试图在行之间传递它们 然后在查找数据集中循环,并为该数据集中的每一行生成一个输出行 现在还不清楚您在这里到底想做什么,因为这不是散列对象的标准用例 这里是我最好的猜测——如果这不是您想要做的,请发布示例输入和预期输出数据集
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;
嗨,谢谢你的回复。你能不能给我一个这样的例子代码,因为我不知道你在说什么。谢谢。我猜了一下你想做什么——如果你不想这样做,请发布一些样本数据。嗨,谢谢你的回复。你能不能给我一个这样的例子代码,因为我不知道你在说什么。谢谢。我猜了一下你想做什么——如果这不是你想要的,请发布一些示例数据。