Note that there are some explanatory texts on larger screens.

plurals
  1. POSAS computation using double loops
    text
    copied!<p>I am trying to compute using two loops. But I am not very familiar with loop elements. </p> <p>Here is my data:</p> <pre><code>data try; input rs t a b c; datalines; 0 600 1 600 0.02514 667.53437 0.1638 2 600 0.2766 724.60233 0.30162 3 610 0.01592 792.34628 0.21354 4 615.2869 0.03027 718.30377 0.22097 5 636.0273 0.01967 705.45965 0.16847 ; run; </code></pre> <p>What I am trying to compute is that for each 'T' value, all elements of a, b, and c need to be used for the equation. Then I create varaibles v1-v6 to put results of the equation for each T1-T6. After that, I create CS to sum all the elements of v. </p> <p>So my result dataset will look like this:</p> <pre><code>rs T a b c v1 v2 v3 v4 v5 v6 CS 0 600 sum of v1 1 600 0.02514 667.53437 0.1638 sum of v2 2 600 0.2766 724.60233 0.30162 sum of v3 3 610 0.01592 792.34628 0.21354 sum of v4 4 615.2869 0.03027 718.30377 0.22097 sum of v5 5 636.0273 0.01967 705.45965 0.16847 sum of v6 </code></pre> <p>I wrote a code below to do this but got errors. Mainly I am not sure how to use i and j properly to link all elements of variables. Can someone point out what i did not think correct? I am aware that myabe I should not use sum function to cum up elements of a variable but not sure which function to use. </p> <pre><code>data try3; set try; retain v1-v6; retain t a b c; array v(*) v1-v6; array var(*) t a b c; cs=0; do i=1 to 6; do j=1 to 6; v[i,j]=(2.89*(a[j]**2*(1-c[j]))/ ((c[j]+exp(1.7*a[j]*(t[i]-b[j])))* ((1+exp(-1.7*a[j]*(t[i]-b[j])))**2)); cs[i]=sum(of v[i,j]-v[i,j]); end; end; run; </code></pre> <hr> <p>Forexample, v1 will be computed like v[1,1] =0 because there is no values for a b c. </p> <p>For v[1,2]=(2.89*0.02514**2(1-0.1638))/((0.1638+exp(1.7*0.02514*600-667.53437)))*((1+exp(-1.7*0.02514*(600-667.5347)))**2)). </p> <p>v[1,3]]=(2.89*0.2766**2(1-0.30162))/((0.30162+exp(1.7*0.2766*600-724.60233)))*((1+exp(-1.7*0.2766*(600-724.60233)))**2)). </p> <p>v[1,4] will be using the next line values of a b c but the t will be same as the t[1]. and do this until the last row. And that will be v1. And then I need to sum all the elements of v1 like v1{1,1] +v1[1,2]+ v1{1,3] ....v1[1,6] to make cs[1,1].</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload