Question about Multi-Array

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Question about Multi-Array

Hi all,

I have a question about arrays.

I have a data set that looks similar to this only much bigger (1000x) I need to calculate the combine scores of [a, b ,c ....n] based on a set equation [ ((n)x + (n)y) - Fixed]. I have created an array for it but I failed to obtain the answer:

The dummy data and the ideal outcome:

Data haveIdeal
Fixedaxaybxbycxcyabc
6132112161110282215
13142115101510221212
1161120191515263829
10141418171717182524
161014101312218717
17191617111320181116
7111215192120162734
2162117111514352627
11201717141220262021
191211101711214813
6122010121713261624

The code:

data have;

input Fixed ax ay bx by cx cy;

datalines;

6 13 21 12 16 11 10

13 14 21 15 10 15 10

1 16 11 20 19 15 15

10 14 14 18 17 17 17

16 10 14 10 13 12 21

17 19 16 17 11 13 20

7 11 12 15 19 21 20

2 16 21 17 11 15 14

11 20 17 17 14 12 20

19 12 11 10 17 11 21

6 12 20 10 12 17 13

;

run;

data want;

set have;

array xcal (*) ax bx cx;

array ycal (*) ay by cy;

array wnt (*) a b c;

do i=1 to dim(xcal);

do j=1 to dim(ycal);

do k=1 to dim(wnt);

wnt(k) = (xcal(i) + ycal(j)) - fixed ;

end;end;end;

drop i j k;

run;

and the wrong outcome:

Fixedaxaybxbycxcyabc
6132112161110151515
13142115101510121212
1161120191515292929
10141418171717242424
16101410131221171717
17191617111320161616
7111215192120343434
2162117111514272727
11201717141220212121
19121110171121131313
6122010121713242424

Could anyone advice me the right method or find out what is wrong with my code please?

Many thanks in advance!

Will


Accepted Solutions
Solution
‎08-19-2014 02:53 PM
Respected Advisor
Posts: 3,775

Re: Question about Multi-Array

You just have too many DOs.

data want;
   set have;
   array xcal
  • ax bx cx;
  •    array ycal
  • ay by cy;
  •    array wnt
  • a b c;
  •    do i=1 to dim(xcal);
          wnt = (xcal + ycal) - fixed ;
         
    end;
      
    drop i;
       run;

    View solution in original post


    All Replies
    Solution
    ‎08-19-2014 02:53 PM
    Respected Advisor
    Posts: 3,775

    Re: Question about Multi-Array

    You just have too many DOs.

    data want;
       set have;
       array xcal
  • ax bx cx;
  •    array ycal
  • ay by cy;
  •    array wnt
  • a b c;
  •    do i=1 to dim(xcal);
          wnt = (xcal + ycal) - fixed ;
         
    end;
      
    drop i;
       run;
    Trusted Advisor
    Posts: 1,203

    Re: Question about Multi-Array

    Hi,

    I think only one do loop will do the job.

    data want;
    set have;
    array xcal (*) ax bx cx;
    array ycal (*) ay by cy;
    array wnt (*) a b c;
    do i=1 to dim(xcal);
    wnt(i) = (xcal(i) + ycal(i)) - fixed ;
    end;
    drop i;
    run;

    proc print data=want;
    run;

    ☑ This topic is SOLVED.

    Need further help from the community? Please ask a new question.

    Discussion stats
    • 2 replies
    • 158 views
    • 3 likes
    • 3 in conversation