楼主: 3qsir
1041 4

How to do use moving MAX [推广有奖]

  • 2关注
  • 1粉丝

副教授

52%

还不是VIP/贵宾

-

威望
0
论坛币
13606 个
通用积分
27.0809
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
71836 点
帖子
367
精华
0
在线时间
931 小时
注册时间
2011-5-18
最后登录
2021-3-6

楼主
3qsir 发表于 2014-3-16 10:57:11 |AI写论文
20论坛币
Hi : Sir
   How to find it (the largest one)  using the 2-moving -MAX windows from pooling data by group ?
THS !

pooling.xls
group          month         sales
1001          199101          1
1001          199102          2
1001          199103          3
1001          199104          4
1003          199102         10
1003          199103           9
1003          199104           8
1003          199105           7
1004          199102          21
1004          199103          21
1004          199104          21
1004          199105          22
1004          199106          23

I hope below:
out.xls
group           month         MAX(2)
1001                   199101           .      
1001                   199102                   2
1001                   199103                   3
1001                   199104                   4
1003                   199102           .
1003                   199103          10
1003                   199104          10
1003                   199105          10
1004           199102            .
1004                   199103                  21
1004                   199104                  21
1004                   199105                  22
1004                   199106                  23

最佳答案

yongyitian 查看完整内容

This is for moving max of 12 rows. I am sure you can change it two, if you want.
关键词:Moving How ING max use moving

沙发
yongyitian 发表于 2014-3-16 10:57:12
This is for moving max of 12 rows. I am sure you can change it two, if you want.
  1. data pooling;
  2.    do group = 1001 to 1003;
  3.    do month = 1 to 30;
  4.       sales = ceil(ranuni(12345)*1000);
  5.       output;
  6.     end; end;
  7. run;

  8. data moving_max;
  9.   array temp{0:11} temp0-temp11;
  10.     i = 0;
  11.     do until (last.group);
  12.       set pooling;
  13.       by group;
  14.                n = mod(i, 12);
  15.           temp[n]= sales;
  16.          maxsale = max(of temp{*});
  17.            do k = 0 to 11;
  18.             if missing(temp[k]) then call missing(maxsale);
  19.            end;
  20.      i+1; output;
  21.     end;
  22.     keep group month sales maxsale;
  23. run;
复制代码
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
3qsir + 5 + 5 + 5 热心帮助其他会员

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

藤椅
yongyitian 发表于 2014-3-16 12:27:17
  1. proc sort data=pooling;
  2.     by group;
  3. run;

  4. data movingmax;
  5.   array temp{2} temp1 temp2 (0 0);
  6.     do until (last.group);
  7.       set pooling ;
  8.       by group;
  9.         if first.group then call missing(maxsale);
  10.           temp[2] = sales;
  11.           maxsale = max(of temp{*});
  12.           temp[1] = temp[2];
  13.           output;
  14.     end;
  15.     drop temp1 temp2;
  16. run;
复制代码

板凳
3qsir 发表于 2014-3-16 13:06:37
Can you rewrite code if temp{12} ?
The 12-moving -MAX windows
THS!
PS: Where is macro %missing in the code?


报纸
3qsir 发表于 2014-3-16 20:35:55
WROMG ! The the first maxsale by group  is = "."  


group               month                sales               maxsale
1001              199101                   1                   1
1001              199102                   2                   2
1001              199103                   3                   3
1001              199104                   4                   4
1003              199102                  10                  10
1003              199103                   9                  10
1003              199104                   8                   9
1003              199105                   7                   8
1004              199102                  21                  21
1004              199103                  21                  21
1004              199104                  21                  21
1004              199105                  22                  22
1004              199106                  23                  23

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

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