BookmarkSubscribeRSS Feed
eemrun
Obsidian | Level 7

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;

 

2 REPLIES 2
RahulG
Barite | Level 11

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;

 

 

eemrun
Obsidian | Level 7
apologies. that was actually a wrong calculation on my end. Had to scrap the approach. Thanks for the help!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1332 views
  • 0 likes
  • 2 in conversation