楼主: 爱萌
3384 7

问:如何在data步中快速计算分组内循环之对数和 [推广有奖]

贵宾

已卖:262份资源

学术权威

54%

还不是VIP/贵宾

-

威望
8
论坛币
96603 个
通用积分
12.3686
学术水平
231 点
热心指数
299 点
信用等级
157 点
经验
102555 点
帖子
6174
精华
1
在线时间
2024 小时
注册时间
2007-3-2
最后登录
2025-12-1

楼主
爱萌 发表于 2013-12-26 09:07:08 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
我有一个方法,需要编写程序,需要改内容
data a;
input x y;
cards;
1 1
1 2
1 3
1 4
1 5
2 3
2 5
2 6
2 7
;
需要按照x分组,以x=1这组来说,我需要log(2/1)+log(3/1)+log(4/1)+log(5/1)+log(3/2)+log(4/2)+log(5/2)+log(4/3)+log(5/3)+log(5/4)这样一个组合的之和,请问该如何最有效率
二维码

扫码加我 拉你入群

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

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

关键词:data步 Data cards Input 编写程序 编写程序 如何

最恨对我说谎或欺骗我的人

沙发
soporaeternus 发表于 2013-12-26 16:48:40
本质是做有条件的笛卡儿积

HASH DATA-STEP SQL都可以做的
Let them be hard, but never unjust

藤椅
yongyitian 发表于 2013-12-26 23:06:36
是不是这个结果
  1. data a;
  2. input x y;
  3. cards;
  4. 1 1
  5. 1 2
  6. 1 3
  7. 1 4
  8. 1 5
  9. 2 3
  10. 2 5
  11. 2 6
  12. 2 7
  13. ; run;

  14. proc transpose data=a out=aa (drop=_name_) prefix=y;
  15.    by x;
  16. run;

  17. data aaa;
  18.    array yy{5} y1-y5;
  19.    set aa;
  20.    m=1;
  21.    do I = 1 to dim(yy)-1 while( yy[I] ^=.);
  22.         do J = I+1 to dim(yy) while (yy[J] ^=.);
  23.            m = m*yy[J]/yy[I];
  24.    end;  end;
  25.    Log_value = log10(m);

  26.    do I = 1 to dim(yy) while(yy[i]^=.);
  27.       y = yy[i];
  28.       output;
  29.    end;
  30.    drop i j y1-y5 m;
  31. run;
复制代码

板凳
jjtww 发表于 2013-12-27 01:32:00
爱萌挖了个大坑,让大家跳呢。
log(a*b)=loga+logb吧。

报纸
邓贵大 发表于 2013-12-27 03:32:26
  1. data a;
  2. input x y;
  3. cards;
  4. 1 1
  5. 1 2
  6. 1 3
  7. 1 4
  8. 1 5
  9. 2 3
  10. 2 5
  11. 2 6
  12. 2 7
  13. ;

  14. data b;
  15.         do count=0 by 1 until(last.x);
  16.                 set a(keep=x);
  17.                 by x;
  18.         end;
  19.                 cumsum=0;
  20.         do _n_ = -count to count by 2;
  21.                 set a;
  22.                 cumsum = cumsum + _n_*log(y);
  23.         end;
  24.         keep x cumsum;
  25. run;
复制代码
已有 2 人评分经验 学术水平 热心指数 信用等级 收起 理由
denver + 100 + 5 + 5 + 5 精彩帖子
pobel + 5 + 5 + 5 精彩帖子

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

Be still, my soul: the hour is hastening on
When we shall be forever with the Lord.
When disappointment, grief and fear are gone,
Sorrow forgot, love's purest joys restored.

地板
爱萌 发表于 2013-12-27 09:26:42
邓贵大 发表于 2013-12-27 03:32
处理的很巧妙,非常感谢,最少的代码干最多的事情
最恨对我说谎或欺骗我的人

7
playmore 发表于 2013-12-27 13:06:33
用笛卡尔积就行,只不过数据量不能很大了

proc sql noprint;
        create table result as
                select a.x,a.y,b.x as x1,b.y as y1
                from a as a,a as b
                where a.x = b.x and a.y < b.y;
quit;

proc sql noprint;
        create table result1 as
                select distinct x,SUM(LOG(y1)/LOG(y)) as logsum
                from result
                group by x;
quit;
playmore邀请您访问ChinaTeX论坛!!!进入ChinaTeX论坛

8
Eternal0601 发表于 2013-12-27 20:10:17
playmore 发表于 2013-12-27 13:06
用笛卡尔积就行,只不过数据量不能很大了

proc sql noprint;
楼主貌似将SUM(LOG(y1/y))敲成SUM(LOG(y1)/LOG(y))了

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-9 05:57