SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

12
返回列表 发新帖
楼主: shiyiming
打印 上一主题 下一主题

请高手过招

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
11#
 楼主| 发表于 2012-2-17 22:57:06 | 只看该作者

Re: 请高手过招

pf! Using hash searching is absolutely right solution to sovle this sort of problem!


[quote="hopewell":znd11mcn][code:znd11mcn]data regular;
    set sample;
    rename child=c parent=highest_parent;
run;
data out(drop=rc c);
    length c highest_parent $8;
    if _n_=1 then do;
        declare hash h(dataset:'regular');
        rc=h.defineKey('c');
        rc=h.defineData('highest_parent');
        rc=h.defineDone();
        call missing(c,highest_parent);
    end;
    set sample;
    highest_parent=parent;
    do while(h.find(key:highest_parent)=0);
    end;
run;[/code:znd11mcn][/quote:znd11mcn]
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
12#
 楼主| 发表于 2012-2-18 22:53:31 | 只看该作者

Re: 请高手过招

深度优先~~跟Oracle的start with ... connect by相似的思路。
精妙的hash,学习了。

我原来都是用广度优先,感觉数据量大的时候不受内存影响,且速度较快,loop的次数有限。看来我的思路都限制在大数据上了。

[quote="hopewell":2rw35q2y][code:2rw35q2y]data regular;
    set sample;
    rename child=c parent=highest_parent;
run;
data out(drop=rc c);
    length c highest_parent $8;
    if _n_=1 then do;
        declare hash h(dataset:'regular');
        rc=h.defineKey('c');
        rc=h.defineData('highest_parent');
        rc=h.defineDone();
        call missing(c,highest_parent);
    end;
    set sample;
    highest_parent=parent;
    do while(h.find(key:highest_parent)=0);
    end;
run;[/code:2rw35q2y][/quote:2rw35q2y]
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2025-5-7 07:23 , Processed in 0.070331 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表