尽管返回非零,但哈希查找方法输入值

编程入门 行业动态 更新时间:2024-10-25 08:23:33
本文介绍了尽管返回非零,但哈希查找方法输入值 - SAS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在数据步骤中使用哈希进行查询,如下所示:

I have a query using hashes in a 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);

我的印象是,如果数据存在,find 方法返回 0,否则返回非零,如果找到数据,它会将其放入表中.但是,这些查询为 rcA 或 rcB 返回非零值,并且仍在输入值.

I'm under the impression that the find method returns 0 if the data exists, non-zero otherwise, and that if data is found it puts it into the table. However, these queries are returning non-zero values for rcA or rcB and still putting in values.

明确地说,如果我的原始表是

Explicitly, if my original table is

UniqueKeyA UniqueKeyB 1 A 2 B 3 C 4 D 5 E

和TableA是

UniqueKeyA DataA 1 'High' 2 'Low' 5 'High

和'TableB是

UniqueKeyB DataA B 'Hot' D 'Cold' E 'Warm'

结果表可能是

UniqueKeyA UniqueKeyB rcA DataA rcB DataB 1 A 0 'High' 42 2 B 0 'Low' 0 'Hot' 3 C 45 'Low' 42 'Hot' 4 D 45 'Low' 0 'Cold' 5 E 0 'High 0 'Warm'

我现在有一个工作

if rcA = 0 then DataA = DataA; if rcA ^= 0 then DataA = ""; if rcB = 0 then DataB = DataB; if rcB ^= 0 then DataB = "";

但这似乎没有必要,因为我认为 find 只有在返回 0 时才会写入表.

But this seems unnecessary, since I thought find only writes to the table if it returns 0.

有人知道为什么会发生这种情况吗?

Does anyone know why this might be happening?

如果您需要更多信息,请告诉我,谢谢!

Please let me know if you need any more information, thanks!

另外,我还有一个关于这些哈希返回整个表而不是指定列的问题,问题在这里:散列返回整个表 - SAS

Also, I have another question about these hashes returning the entire table rather than the specified column, the question is here: Hash returning entire table - SAS

推荐答案

这是同一个东西的另一个副作用 - if 0 then set tableA.

This is another side effect of the same thing - if 0 then set tableA.

任何通过SET、MERGE或UPDATE语句到达数据步骤的变量将自动RETAINed,这意味着它不会在数据步循环开始时设置为缺失.所以你要么需要放弃 if 0 然后设置 tableA/B 行(你可以用几个 length 语句替换它们,每个散列中的每个变量一个)或者做你在做什么,手动将它们设置为缺失.

Any variable that arrives in the data step through a SET, MERGE, or UPDATE statement will be automatically RETAINed, which means that it won't be set to missing at the start of the data step loop. So you either need to abandon the if 0 then set tableA/B lines (you can replace them with a couple of length statements, one per variable in each hash) or do what you're doing, set them to missing manually.

更多推荐

尽管返回非零,但哈希查找方法输入值

本文发布于:2023-11-02 08:06:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551839.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!