03-24-2018 07:43 PM
Within a DATA step, and assuming you have variables A, B, and N:
do k=1 to n;
y + a*b**(-k);
If B is actually an expression rather than a variable, put it in parentheses:
y + a*(b)**(-k);
03-26-2018 08:23 PM
Thanks for you both for providing the answer, much appreciated! PG Stats, since the power is negative, should the sas code be revised?
as u = 0;
v = 1/b;
do k = -1 to -n; u = (1 + u) * v; end;
y = a*u;
Thanks and regards.
03-27-2018 04:26 PM
No. k is only a counter, not the exponent. The exponent comes from the number of multiplications by v (= 1/b, = b**-1), i.e. the negative exponent results from multiplying by a negative power of b.
03-28-2018 03:56 PM
In the equation, everything is the same, only if N is not an integer, the example is below and I need to calculate for each record (Y1........YN)
Y1=A*(B)-1+ A*(B)-2 + A*(B)-3 + A*(B)-4 +……+ A*(B)-10.2
Y2=A*(B)-1+ A*(B)-2 + A*(B)-3 + A*(B)-4 +……+ A*(B)-20.3
YN=A*(B)-1+ A*(B)-2 + A*(B)-3 + A*(B)-4 +……+ A*(B)-N.5
03-28-2018 10:31 PM
Thanks very much, PG!
the term before the last is: A*(B)-N+1
Y1=A*(B)-1+ A*(B)-2 + A*(B)-3 + A*(B)-4 +……+ A*(B)-9 +A*(B)-10.2
When I run the above sas code, the decimal 0.2 from the last term is missing.