|
On Thu, Sep 4, 2008 at 5:19 AM, kunal <kunal.krishnan@gmail.com> wrote:
> Hi guys,
>
>
> data piecatg.test;
> input obs a b;
> cards;
> 1 34 45
> 2 65 56
> 3 43 65
> 4 56 56
> 5 89 21
> 6 45 65
> 7 12 34
> 8 44 45
> 9 34 78
> 10 23 23
> ;
> run;
>
>
> data piecatg.automated_array_new;
>
> array x[0:11] _temporary_ ;
> array y[0:11] _temporary_ ;
> /*input id y{*};*/
> do i=1 to 10 by 1;
> set piecatg.test;
> y[i] = b;
> x{i}= x{i-1}+y{i};
> pred = x{i};
> output;
> end;
> run;
>
>
>
> I am using the above code to generate values in a new column which
> should give the following output "pred":
>
> 45
> 101
> 166
> 222
> 243
> 308
> 342
> 387
> 465
> 488
>
>
> where "pred" is being calculated as pred{i} = pred{i-1} + b {i}
>
> for eg: for data
>
> 45
> 56
> 65
>
> o/p window should be
>
> a b
> 45 45
> 56 101
> 65 166
>
> where
> b{0} = a{0}
> b{1} = b{0} + a{1}
> b{2} = b{1} + a{2} and so on
>
>
> can any1 please let me know why am i getting missing values in pred
> when i run the code?? is there something wrong with the logic??
>
> Thanks
>
Kunal
It looks that you do not require the use of any array at all.
data test;
input obs a b;
cards;
1 34 45
2 65 56
3 43 65
4 56 56
5 89 21
6 45 65
7 12 34
8 44 45
9 34 78
10 23 23
;
run;
data need;
set test;
if _n_ = 1 then pred = b;
else pred + b;
run;
|