SAS中文论坛

标题: 利用一列row1里数据求下面row的数 --- 也想求一名sas 高手, 以后可以随时回到出现的一些问题。合理付费! [打印本页]

作者: shiyiming    时间: 2009-5-25 23:12
标题: 利用一列row1里数据求下面row的数 --- 也想求一名sas 高手, 以后可以随时回到出现的一些问题。合理付费!
请高手指导! 也想求一名sas 高手, 以后可以随时回到出现的一些问题。合理付费!


i have a time series data file that has about 3.5million observations. to give an example, the original data looks like this:

Column1:  Column2:  Column3:
x              c1            t1
y              c2            t2
.               c3            t3
.               c4            t4

in Column1, i have values X, Y, respectively in the first two rows. the rest of the rows in Column1 is empty. i want to use X and Y (values in the first two rows of Column1) to generate value for all the other rows in Column1, using the formula Column2 * (Column3 - lag2(column1)) + lag2(column1)

for example, to get the value for Column1, row 3, we want to take the lag2 value of the row, which is x, and do C3 *(t3-x)+x.   for Column1, row 4, it should be C4 *(t4-y)+y

we want to finished data to be like this

Column1:
x
y
C3 *(t3-x)+x
C4 *(t4-y)+y
C3 *(t3-(C3 *(t3-x)+x))+(C3 *(t3-x)+x)
C4 *(t4-(C4 *(t4-y)+y))+(C4 *(t4-y)+y)
.
.
.

i have tried doing something like:

if row>2 thencolumn1 = lag2(Column1)

but it doesn't work.

Can you figure something out?  Thanks!
作者: shiyiming    时间: 2009-5-25 23:48
标题: Re: 利用一列row1里数据求下面row的数 --- 也想求一名sas 高手, 以后可以随时回到出现的一些问题。合理付费!
我也遇到过这样的问题,跪求达人指教。
作者: shiyiming    时间: 2009-5-26 10:05
标题: Re: 利用一列row1里数据求下面row的数 --- 也想求一名sas 高手, 以后可以随时回到出现的一些问题。合理付费!
你试着去添加一个column,然后用这个column去记录行数。比如讲,这个column的名字叫obs。你就可以用:
if obs>2 then......
作者: Qiong    时间: 2009-5-26 11:54
标题: Re: 利用一列row1里数据求下面row的数 --- 也想求一名sas 高手, 以后可以随时回到出现的一些问题。合理付费!
You may try the below code.
[code:ks1nnmin]data temp;
input y c t;
cards;
1 2 3
2 3 4
. 5 6
. 7 8
. 9 10
. 100 10
;
run;

data v;
retain la1 la2;
set temp;
x=lag(y);
if _n_=2  then do;
la2=x;
la1=y;
end;
if _n_>=3   then do;
y=c*(t-la2)+la2;
la2=la1;
la1=y;
end;
keep y c t;
run; [/code:ks1nnmin]




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