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!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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