楼主: cherrystrawbery
3155 13

[原创博文] 请教均值计算 [推广有奖]

11
cherrystrawbery 发表于 2012-2-25 20:19:02
yugao1986 发表于 2012-2-23 11:44
mysas论坛有过关于移动平均的讨论,我记录下来了,你可以看看.http://blog.csdn.net/yugao1986/article/det ...
给力,很有用,多谢!

12
cherrystrawbery 发表于 2012-2-25 20:21:09
sunset1986 发表于 2012-2-24 11:32
%let p=12;
data c (drop=i b1-b&p.);
        set a;
多谢,强。。。

13
sunset1986 发表于 2012-2-25 23:06:42
cherrystrawbery 发表于 2012-2-25 20:21
多谢,强。。。
呵呵,客气
An honest tale speeds best being plainly told.
Cheers!

14
sunset1986 发表于 2012-3-1 09:58:28
sunset1986 发表于 2012-2-24 11:32
%let p=12;
data c (drop=i b1-b&p.);
        set a;
楼主,不好意思,上面这段代码没有办法实现分段均值,进行了调整:

%let p=12;
data e (drop=i j);
        set a;
        if balance ne '.';
        n+1;
        by cid;
/*        (n指代每组的序号)*/
        if first.cid then n=1;
        array a[&p.] b1-b&p.;
        a[1]=lag(balance);
        do i=2 to &p.;
                a=lag(a[i-1]);
        end;
       
        j=&p.;
        do until (j=0);
        if(n<=j) then a(j)=.;
        j=j-1;
        end;

        mean6=mean(of b1-b6);
        mean12=mean(of b1-b12);
run;

/*        j=&p.; */
/*        do until (j=0); */
/*        if(n<=j) then a(j)=.; */
/*        j=j-1; */
/*        end; */

上面这段是新加入的代码,我觉得基本可以满足要求了,楼主先再尝试下~
An honest tale speeds best being plainly told.
Cheers!

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

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