【发布时间】:2018-04-04 15:38:22
【问题描述】:
文件A:
C1(name) C2(other name)
Apple Fruit_1 Fruit_2
Orange Fruit_1 Fruit_2
Carrot Vegetable_1 Vegetable_2
Potato Vegetable_1 Vegetable_2
文件 B:
C1(name) C2 (last used)
Apple 2014
Fruit_1 2011
Carrot 2010
Vegetable_2 2018
期望的结果:
C1(name) C2(other name) C3(last used)
Apple Fruit_1 Fruit_2 2014
Orange Fruit_1 Fruit_2 2011
Carrot Vegetable_1 Vegetable_2 2018
Potato Vegetable_1 Vegetable_2 2018
基本上我想根据第一个文件中的两列组合我的文件。如果在文件 a 的 C1 或 C2 列中找到文件 b 的“名称”,则附加日期。请注意,对于胡萝卜,日期与土豆相同,这是因为蔬菜_2 具有最近的日期,而蔬菜_2 可以指胡萝卜或土豆。
在我的 MERGE 测试中,我无法合并以检查第二列,因此我只能获取两个文件中 C1 中存在的项目的数据。
所以我目前的结果是:
C1(name) C2(other name) C3(last used)
Apple Fruit_1 Fruit_2 2014
Orange Fruit_1 Fruit_2
Carrot Vegetable_1 Vegetable_2 2010
Potato Vegetable_1 Vegetable_2
您知道可以使用什么 SAS 流程来获得我想要的结果吗?仅供参考,我在大型机上使用 SAS。我不确定这是否会改变任何东西,因为我没有在大型机环境之外使用过 SAS。
【问题讨论】:
-
这需要 SQL 或哈希解决方案,SQL 可能更简单。请发布您迄今为止为解决此问题所做的任何尝试。