Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7793399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:28:37+00:00 2026-06-01T22:28:37+00:00

I am trying to compute using two loops. But I am not very familiar

  • 0

I am trying to compute using two loops. But I am not very familiar with loop elements.

Here is my data:

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;

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.

So my result dataset will look like this:

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

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.

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;

Forexample, v1 will be computed like v[1,1] =0 because there is no values for a b c.

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)).

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)).

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].

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:28:39+00:00Added an answer on June 1, 2026 at 10:28 pm

    The SAS language isn’t that good at doing these kinds of things, which are essentially matrix calculations. The DATA step normally processes one observation at a time, though you can carry calculations over using the RETAIN statement. It is possible that you could get a cleaner result than this if you had access to PROC IML (which does matrix calculations natively), but assuming that you don’t have access to IML, you need to do something like the following. I’m not 100% sure that it is what you need, but I think it is along the right lines:

        data try;
         infile cards missover;
         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;
    
        data try4(rename=(aa=a bb=b cc=c css=cs tt=t vv1=v1 vv2=v2 vv3=v3 vv4=v4 vv5=v5 vv6=v6));
        * Construct arrays into which we will read all of the records;
        array t(6);
        array a(6);
        array b(6);
        array c(6);
        array v(6,6);
        array cs(6);
    
        * Read all six records;
        do i=1 to 6;
          set try(rename=(t=tt a=aa b=bb c=cc));
          t[i] = tt;
          a[i] = aa;
          b[i] = bb;
          c[i] = cc;
        end;
    
        * Now do the calculation, which involves values from each
          row at each iteration;
        do i=1 to 6;
          cs[i]=0;
          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]+v[i,j];
          end;
    
          * Then output the values for this iteration;
          tt=t[i];
          aa=a[i];
          bb=b[i];
          cc=c[i];
          css=cs[i];
          vv1=v[i,1];
          vv2=v[i,2];
          vv3=v[i,3];
          vv4=v[i,4];
          vv5=v[i,5];
          vv6=v[i,6];
          keep tt aa bb cc vv1-vv6 css;
          output try4;
         end;
    

    Note that I have to construct arrays of known size, that is you have to know how many input records there are.

    The first half of the DATA step constructs arrays into which the values from the input data set are read. We read all of the records, and then we do all of the calculations, since we have all of the values in memory in the matricies.
    There is some fiddling with RENAMES so that you can keep the array names t, a, b, c etc but still have variables named a, b, c etc in the output data set.

    So hopefully that might help you along a bit. Either that or confuse you because I’ve misunderstood what you’re trying to do!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to compute confidence intervals for groups with a common model using lmList
i'm trying to get computer's state in my LAN... thought about using QTcpSocket but
I went into this understanding this would not work, but I am trying to
x= [0,2,3,5,6]; y= [64,384,1024,4096,384]; The above are two arrays I'm using. Im trying to
I am trying to use Difflib.SequenceMatcher to compute the similarities between two files. These
I'm trying to simulate a particle system using OpenGl but I can't get it
I need to be able to compute differences between two data/time values which represent
I am trying to access an ec2 instance using a different (mac) computer. In
Im trying to compute a 24 hour rms (root mean squared) from a dataset
I am trying to compute the hash of a byte array in Java. To

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.