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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.