Rookie here. I am trying to evaluate the following. The idea is that this should evaluate lp with an initial value (given in the first equation) and then loop to populate with those fixed values (e.g. kA, kB) and array values of A, B, C values. Initial values are zero for array AX, BX and CX. When I run it, i get zeroes for all instances of A, B and C and no LP values. Any idea where i am wrong?
data test1 (drop = i);
array AX[128] A1-A128;
array BX[128] B1-V128;
array CX[128] C1-T128;
do i = 1 to 128;
AX[i] = 0;
BX[i] = 0;
CX[i] = 0;
end;
run;
data test2 ;
set test1;
array AX[128] A1-A128;
array BX[128] B1-V128;
array CX[128] C1-T128;
kA = 23.99196;
kB = 21.04797;
kC = 54.98294;
lp = (log(kA) * 127/2) + (log(kB) * 127/2) + (log(kC) * 127/2);
do i=2 to 128;
lp = lp - kA * (AX[i] - AX[i-1])**2 / 2
- kB * (BX[i] -BX[i-1])**2 / 2
- kC * (CX[i] - CX[i-1])**2 / 2;
end;
run;
Few typos in the code, please correct it.
B1-V128 should be B1-B128
C1-T128 should be C1-C128
After this correction, if I run the code I get lp =649.70316134 because of first equation
lp = (log(kA) * 127/2) + (log(kB) * 127/2) + (log(kC) * 127/2);
Rest main loop is not helping becuase all A1-A128, B1-B128 and C1-C128 are zero.
Let me know what are you looking for.
data test1 (drop = i);
array AX[128] A1-A128;
array BX[128] B1-B128;
array CX[128] C1-C128;
do i = 1 to 128;
AX[i] = 0;
BX[i] = 0;
CX[i] = 0;
end;
run;
data test2(keep=lp) ;
set test1;
array AX[128] A1-A128;
array BX[128] B1-B128;
array CX[128] C1-C128;
kA = 23.99196;
kB = 21.04797;
kC = 54.98294;
lp = (log(kA) * 127/2) + (log(kB) * 127/2) + (log(kC) * 127/2);
do i=2 to 128;
lp = lp - kA * (AX[i] - AX[i-1])**2 / 2
- kB * (BX[i] -BX[i-1])**2 / 2
- kC * (CX[i] - CX[i-1])**2 / 2;
end;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.