散列返回整个表 - SAS [英] Hash returning entire table - SAS
问题描述
我在数据步骤中使用散列进行查询,如下所示:
I have a query using a hash in the data step as follows:
if _n_ = 1 then do;
if 0 then
set TableA;
declare hash A(dataset: "TableA");
A.definekey ("UniqueKeyA" );
A.definedata ("DataA" );
A.definedone();
end;
if _n_ = 1 then do;
if 0 then
set TableB;
declare hash B(dataset: "TableB");
B.definekey ("UniqueKeyB" );
B.definedata ("DataB" );
B.definedone();
end;
rcA = A.find(key:UniqueKeyA);
rcB = B.find(key:UniqueKeyB);
当我运行查询时,TableA
按预期返回 rcA
和数据,但是 TableB
的散列由于某种原因带来了每一列来自 TableB
.这些查询在我看来是相同的,我想不出这些表之间有什么性质上的不同会导致它们的行为不同,但我对 SAS 了解不多.
When I run the query, TableA
returns rcA
and the data as expected, but the hash for TableB
for some reason brings every column from TableB
with it. These queries look identical to me and I can't think of anything qualitatively different between the tables that would cause them to act differently, but I don't know much about SAS.
明确地说,如果我的原始表是
Explicitly, if my original table is
UniqueKeyA UniqueKeyB
1 A
2 B
3 C
表A是
UniqueKeyA [...Other TableA columns...] DataA
1 53
3 ... 46
表B是
UniqueKeyB [...Other TableB columns...] DataB
B .45
C ... .22
我的结果表是
UniqueKeyA UniqueKeyB rcA DataA rcB [...Other TableB columns...] DataB
1 A 0 53 21
2 B 513 0 .45
3 C 0 46 0 ... .22
这对我来说没有意义,因为散列看起来非常基本,尽管它们相同,但只有其中一个返回每一列.
This doesn't make sense to me, since the hashes seem very basic, and although theyre identical only one of them returns every column.
如果您需要更多信息,请告诉我,谢谢!
Please let me know if you need more information, thanks!
此外,我还有另一个问题是关于这些相同的哈希值将值输入到数据列中,例如,rcA
不等于 0.这个问题在这里:尽管返回非零,但哈希查找方法输入值 - SAS>
Also, I have another question about these same hashes entering values into the data column even though, for example, rcA
doesn't equal 0. That question is here: Hash find method entering values despite returning non-zero - SAS
推荐答案
这一行:
if 0 then
set TableB;
是列的来源.这是一种懒惰"的方法,可以避免在哈希创建之前没有在技术上初始化变量的内容时出现未初始化的变量消息.如果你把每个变量都带进来就好了,但当然,如果你只带了 2 个而你有 40 个,你会得到 38 个你不太想要的额外的.它们是空的,但仍然不需要.
is where the columns come from. This is a 'lazy' way of avoiding the uninitialized variable message that would appear from the hash creation if there isn't something technically initializing the variables before the hash. It's fine if you are bringing every variable in, but of course if you're only bringing 2 and you have 40, you get 38 extras that you don't much want. They're empty, but still unneeded.
将 (keep=uniquekey datab)
添加到 set TableB 语句中,它应该去掉那些其他列.
Add (keep=uniquekey datab)
to the set TableB statement and it should get rid of those other columns.
这篇关于散列返回整个表 - SAS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!