SAS中文论坛

标题: a=a*lag(a) How could I realize this function? [打印本页]

作者: shiyiming    时间: 2006-3-14 16:39
标题: a=a*lag(a) How could I realize this function?
I have tried:
a=a*lag(a);
But it seems not working.

I want make the variables multiply continuous.


1
3
4
2
...
I want it to be
1
3
12
24
...
作者: shiyiming    时间: 2006-3-14 17:28
标题: Reply: a=a*lag(a) How could I realize this function?
when _n_=1, lag(a) seems to be missing value.

then could add one extra condition to exclude this case occurance like when _n_ ge 1 then a*lag(a).

Try it. hope it could work!   <!-- s:lol: --><img src="{SMILIES_PATH}/icon_lol.gif" alt=":lol:" title="Laughing" /><!-- s:lol: -->
作者: shiyiming    时间: 2006-3-14 17:57
标题: 试过了,不行。
试过了,不行。

谁能帮忙写个代码把这个算一下?

1
2
3
4
。。。

1
2
6
24
。。。
作者: shiyiming    时间: 2006-3-15 09:24
标题: 试试
[code:8dded]data ahuige;
  input a;
  retain s 1;
  s=s*a;
  cards;
1
3
4
2
;
run;[/code:8dded]
作者: shiyiming    时间: 2006-3-15 21:16
标题: Now test it.
%let n=2;
data mutiply (drop=s);
  retain s;
  set test;
  s = sum(s,log(x), -log(lag&n(x))) ;
  moving_product=exp(s);
run;

proc print;
run;
作者: shiyiming    时间: 2006-3-16 17:03
标题: 多谢各位。
多谢各位。




欢迎光临 SAS中文论坛 (http://mysas.net/forum/) Powered by Discuz! X3.2