楼主: flyinglancet
7164 9

[问答] sas hash表的 汇总问题 [推广有奖]

  • 0关注
  • 1粉丝

硕士生

13%

还不是VIP/贵宾

-

威望
0
论坛币
123 个
通用积分
0
学术水平
0 点
热心指数
2 点
信用等级
0 点
经验
2548 点
帖子
57
精华
0
在线时间
187 小时
注册时间
2008-3-12
最后登录
2021-4-9

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
各位大虾:
在sas/hash中碰到下面一个问题,一直苦于无法解决,请各位大虾帮忙:
例如(实际客户上万个):A客户有三条记录,每条记录的金额均小于200,;B客户有5条记录,每条记录的金额均大于150,但小于400。
在hash中,如何实现下面条件?
条件:如果某个客户的总金额(该客户所有记录的金额加和)<600,则将该客户的所有记录删除。
如上例中,A客户总金额<600,则删除A客户。

不用sql解决,只用sas/hash解决,并且一步实现
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:HASH Has 总问题 如何实现 下面条 汇总 SAS HASH

回帖推荐

pobel 发表于2楼  查看完整内容

data test; input id $ amount; datalines; A 189 B 160 B 188 B 165 A 145 A 199 B 198 B 345 ; data wanted; if 0 then set test; if _n_=1 then do; declare hash h(); h.definekey('id'); h.definedata('id','total'); h.definedone(); end; do until(last); set test end=last; if h.find()=0 then do; total+amount; h.rep ...
已有 1 人评分热心指数 收起 理由
eijuhz + 2 精彩帖子

总评分: 热心指数 + 2   查看全部评分

本帖被以下文库推荐

沙发
pobel 在职认证  发表于 2010-12-3 17:27:58 |只看作者 |坛友微信交流群
data test;
     input id $ amount;
     datalines;
A  189
B  160
B  188
B  165
A  145
A  199
B  198
B  345
;


data wanted;
    if 0 then set test;
    if _n_=1 then do;
            declare hash h();
                    h.definekey('id');
                        h.definedata('id','total');
                        h.definedone();
        end;
        do until(last);
            set test end=last;
                if h.find()=0 then do;
            total+amount;
                        h.replace();
                end;
                else do;
                     total=amount;
             h.add();
                end;
         end;
         do until(last1);
         set test end=last1;
                 if h.find()=0 and total>=600 then output;
         end;
         drop total;
         stop;
run;
已有 3 人评分学术水平 热心指数 信用等级 收起 理由
醉_清风 + 1 + 1 + 1 灵的
飘洒 + 1 + 1 + 1 学习了
soporaeternus + 1 + 1 + 1 学习了

总评分: 学术水平 + 3  热心指数 + 3  信用等级 + 3   查看全部评分

和谐拯救危机

使用道具

藤椅
flyinglancet 发表于 2010-12-7 10:14:10 |只看作者 |坛友微信交流群
非常感谢,再多问一句,如果有另一个表(test1),内有字段id、name等,想用一个data步实现关联和筛选,我写的程序如下,结果是name一栏全为空?:
data wanted;
    if 0 then set test1;
    if _n_=1 then do;
        declare hash h();
                h.definekey('id');
                h.definedata('id','name','total');
                h.definedone();
    end;
    do until(last);
        set test end=last;
        if h.find()=0 then do;
            total+amount;
            name=name;
            h.replace();
         end;
         else do;
             total=amount;
             name=name;
             h.add();
         end;
     end;
     do until(last1);
         set test end=last1;
         if h.find()=0 and total>=600 then output;
     end;
     drop total;
     stop;
run;

使用道具

板凳
pobel 在职认证  发表于 2010-12-7 10:47:17 |只看作者 |坛友微信交流群
data test;
     input id $ amount;
     datalines;
A  189
B  160
B  188
B  165
A  145
A  199
B  198
B  345
;

data test1;
    input id $ name $;
datalines;
A Jose
B Hose'B'
;

data wanted;
    if 0 then set test test1;
    if _n_=1 then do;
            declare hash h();
                    h.definekey('id');
                        h.definedata('id','total');
                        h.definedone();

            declare hash h_name(dataset:'test1');
                    h_name.definekey('id');
                        h_name.definedata('id','name');
                        h_name.definedone();
        end;
        do until(last);
            set test end=last;
                if h.find()=0 then do;
            total+amount;
                        h.replace();
                end;
                else do;
                     total=amount;
             h.add();
                end;
         end;
         do until(last1);
               set test end=last1;
               if h.find()=0 and total>=600 then do;
                        h_name.find();
                        output;
                end;
         end;
         drop total;
         stop;
run;
已有 3 人评分学术水平 热心指数 信用等级 收起 理由
Tigflanker + 1 + 1 + 1 晕眩。。
beci426 + 1 + 1 + 1 nb
jingju11 + 1 + 1 + 1 这么长,恨不得每项+3,只是权力有限啊

总评分: 学术水平 + 3  热心指数 + 3  信用等级 + 3   查看全部评分

和谐拯救危机

使用道具

报纸
flyinglancet 发表于 2010-12-7 11:46:27 |只看作者 |坛友微信交流群
谢谢!

使用道具

地板
醉_清风 发表于 2010-12-7 20:32:01 |只看作者 |坛友微信交流群
学习了
hash我还是停留在小表连大表速度快的应用上
从来不需要想起 永远也不会忘记

使用道具

7
ladyw 发表于 2011-3-19 13:56:31 |只看作者 |坛友微信交流群
楼主,你好,请问hash、hiter类能否在SAS8版本中使用?我把上面的代码原封不动的搬到PGM窗口运行,错误如下:
                 180
NOTE: SCL source line.
230                      h.definekey('id');
                                    -
                                    22
ERROR: Invalid variable specification, h.definekey.
        Variable names of the form X.X must be either FIRST.X or LAST.X
NOTE: SCL source line.
231                          h.definedata('id','total');
                                         -
                                         22
                                         76
ERROR: Invalid variable specification, h.definedata.
        Variable names of the form X.X must be either FIRST.X or LAST.X
只写上面这些了,楼主帮我找下原因吧

使用道具

8
beci426 发表于 2013-5-7 23:40:19 |只看作者 |坛友微信交流群
mark下

使用道具

9
sniperhgy 发表于 2013-8-29 11:41:51 |只看作者 |坛友微信交流群
学习了一下,谢谢各位前辈。

使用道具

10
eric_darcy 发表于 2018-9-7 14:28:58 |只看作者 |坛友微信交流群
学习鸟~~~

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-19 20:57