BookmarkSubscribeRSS Feed
desireatem
Pyrite | Level 9

S(t)     X_i

.91        1

.85        2

.76       3

.61       4

.55      5

How to I compute this from data above.?

Z=SUM(S(X_i)-S_i+1)*(X_i+1 - X_i)

Z=(0.91-0.85)(2-1)  +  (0.85-0.76)(3-2) + (0.76-0.61)(4-3) + (0.61-0.55)(5-4)

Z=SUM[(S(X_i)-S_i+1) * (X_i+1 - X_i)]

Please in case of simulations

In a general setting such that;

For Example how do I used the code above for this case that I simulate;

Data test;

Do i=1 to 100;

S(t)=ranexp(0)/3;

X_i= ranexp(0)/2;

Output;

End;

Thanks

1 REPLY 1
Vince28_Statcan
Quartz | Level 8

Since this is the IML subforum, lets assume your data is stored in a matrix named SDATA.

Z=0;

do i=1 to (nrow(SDATA)-1);

     Z=Z+(SDATA[i,1]-SDATA[i+1,1])*(SDATA[i+1,2]-[SDATA[i,2]);

end;

print Z;

a more efficient way would probably be to use 4 temporary matrices of dimension (nrow(SDATA)-1)  and define them like X1=SDATA[1:nrow(SDATA)-1,2], X2=SDATA[2:nrow(SDATA), 2] etc. and use term by term multiplication operator which I forgot on the top of my head as it's been a while since I've used IML. More memory usage but fewer operations.

if you want to do this in regular SAS, look for lag<n> function, in your case lag1 function.


Vincent

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!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 1 reply
  • 784 views
  • 0 likes
  • 2 in conversation