请选择 进入手机版 | 继续访问电脑版
楼主: dxystata
1797 6

[有偿编程] 如何得到每个个体在不同时间点的均值 [推广有奖]

版主

大师

34%

还不是VIP/贵宾

-

TA的文库  其他...

Software

中英文Ebook

R学习

威望
2
论坛币
181723 个
通用积分
15202.5562
学术水平
208 点
热心指数
271 点
信用等级
174 点
经验
289847 点
帖子
5343
精华
1
在线时间
13444 小时
注册时间
2006-6-21
最后登录
2024-3-28

初级学术勋章 初级热心勋章

dxystata 发表于 2017-5-15 14:11:54 |显示全部楼层 |坛友微信交流群
20论坛币
  1. data aaa;
  2. input no time x;
  3. cards;
  4. 1 8 1
  5. 1 8 2
  6. 1 9 1
  7. 1 9 2
  8. 1 9 3
  9. 1 10 2
  10. 2 8 4
  11. 2 9 5
  12. 2 9 6
  13. 2 9 7
  14. ;
  15. run;

  16. /* 希望得到的数据 */
  17. 1 8 1.5
  18. 1 9 2
  19. 1 10 2
  20. 2 8 4
  21. 2 9 6
复制代码
如何得到每个个体(id)在不同时间点(time)x的均值?谢谢!

最佳答案

l12345q 查看完整内容

proc sql; select no,time,avg(x) as avg from aaa group by no,time; quit;
关键词:Input cards time Data card 如何
l12345q 发表于 2017-5-15 14:11:55 |显示全部楼层 |坛友微信交流群
proc sql;
select no,time,avg(x) as avg from aaa  group by no,time;
quit;

使用道具

proc sql noprint;
create table want as
select no,time,mean(x) as mean from have group by no,time order by no,time;
quit;
已有 1 人评分经验 热心指数 收起 理由
dxystata + 100 + 1 精彩帖子

总评分: 经验 + 100  热心指数 + 1   查看全部评分

使用道具

proc sql noprint;
create table want as
select no,time,mean(x) as mean from have group by no,time order by no,time;
quit;
已有 1 人评分经验 热心指数 收起 理由
dxystata + 100 + 1 精彩帖子

总评分: 经验 + 100  热心指数 + 1   查看全部评分

使用道具

都是用SQL的 提供一个data步的思路
  1. data aaa1;
  2.         set aaa;
  3.         by no time;
  4.         retain x_ n_;
  5.         if first.time then do; x_=0; n_=0; end;
  6.         x_=x+x_;
  7.         n_+1;
  8.         y=x_/n_;
  9.         if last.time;
  10.         keep no time y;
  11. run;
复制代码
已有 1 人评分经验 热心指数 收起 理由
dxystata + 100 + 1 精彩帖子

总评分: 经验 + 100  热心指数 + 1   查看全部评分

使用道具

albusdzx 发表于 2017-5-16 14:16:30 |显示全部楼层 |坛友微信交流群
data bbb(keep=no time mean);
set aaa;
by no time;
if first.no and first.time then do; num=0; total=0; end; /*防止上一号最大time与下一号最小time相同*/
if first.time then do; num=0; total=0; end;
total+x;
num+1;
if  last.time then do;
mean=total/num; output;
end;
run;
已有 1 人评分经验 热心指数 收起 理由
dxystata + 100 + 1 精彩帖子

总评分: 经验 + 100  热心指数 + 1   查看全部评分

使用道具

learsaas 发表于 2017-5-16 14:24:46 |显示全部楼层 |坛友微信交流群
datastep ,proc sql,proc means ,proc summary,proc iml太多了。。。。。。。。。。
已有 1 人评分经验 热心指数 收起 理由
dxystata + 100 + 1 精彩帖子

总评分: 经验 + 100  热心指数 + 1   查看全部评分

使用道具

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

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

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

GMT+8, 2024-3-28 19:07