哈希返回整个表 - SAS [英] Hash returning entire table - SAS

查看:22
本文介绍了哈希返回整个表 - 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

TableA 是

UniqueKeyA    [...Other TableA columns...]   DataA
    1                                          53
    3                    ...                   46

TableB 是

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆