0

I have problem with Multidimensional Array. I created calculate between two types of data from one table. Example data from table BT_MATRYCA. And I division data from TYP: VAL_A since COL1 to COL17 by value from SUMA_RAZEM from row with TYP: VAL_B.

Command "put d_st[i,j] =;" puts good value but I need create table with this calculate (Multidimensional, with X and Y). How I can do?

data BT_MATRYCA;
infile DATALINES dsd missover;
input NAME $ TYP $ COL1 COL2 COL3 COL4 COL5 COL6 COL7 COL8 COL9 COL10 COL11 COL12 COL13 COL14 COL15 COL16 COL17 SUMA_RAZEM;
CARDS;
A1, VAL_A, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 500
A1, VAL_B, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 600
B1, VAL_A, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 13, 14, 15, 16, 16, 20, 550
B1, VAL_B, 1, 20, 3, 20, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 800
C1, VAL_A, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 30, 12, 13, 14, 15, 16, 17, 900
C1, VAL_B, 1, 2, 3, 20, 5, 6, 7, 8, 02, 10, 11, 12, 30, 14, 15, 16, 17, 780
;run;


data t3;
array m[6,18] _temporary_;
array n[6,18] _temporary_;
array d_st[6,18] _temporary_;
call missing(of d_st[*]);

if _n_ = 1 then do;
   do i = 1 by 1 until(z1);
      set BT_MATRYCA (where=(TYP = 'VAL_A')) end = z1;
      array c[18] COL1--SUMA_RAZEM;
      do j = 1 to 18;
         m[i, j] = c[j];
      end;
   end;

   do i = 1 by 1 until(z2);
      set BT_MATRYCA (where=(TYP = 'VAL_B')) end = z2;
      array v[18] COL1--SUMA_RAZEM;
      do j = 1 to 18;
         n[i,j] = v[j];
      end;
  end;
end;

do i = 1 to 6;
   do j = 1 to 18;
        IF m[i,18] ne 0 then
            d_st[i,j] = coalesce((n[i,j] / m[i,18]),0);
        ELSE
            d_st[i,j] = 0;
   end;
end;

do i = 1 to 6;
   do j = 1 to 18;
      put d_st[i,j] =;
   end;
end;
stop;
run;

`

1
  • You need to add OUTPUT statements so that your records get written out to the data set. Commented May 22, 2019 at 15:13

1 Answer 1

1

It isn't particularly clear what you're asking, but it sounds as though you want something like this:

data t3 wide(keep = x1-x6) long(keep = x y z);
array m[6,18] _temporary_;
array n[6,18] _temporary_;
array d_st[6,18] _temporary_;
array _x[6] x1-x6;

put d_st[1,1]=;

if _n_ = 1 then do;
   do i = 1 by 1 until(z1);
      set BT_MATRYCA (where=(TYP = 'VAL_A')) end = z1;
      array c[18] COL1--SUMA_RAZEM;
      do j = 1 to 18;
         m[i, j] = c[j];
      end;
   end;

   do i = 1 by 1 until(z2);
      set BT_MATRYCA (where=(TYP = 'VAL_B')) end = z2;
      array v[18] COL1--SUMA_RAZEM;
      do j = 1 to 18;
         n[i,j] = v[j];
      end;
  end;
end;

do i = 1 to 6;
   do j = 1 to 18;
        IF m[i,18] ne 0 then
            d_st[i,j] = coalesce((n[i,j] / m[i,18]),0);
        ELSE
            d_st[i,j] = 0;
   end;
end;

/* Note switching of inner and outer loops*/
do j = 1 to 18;
  do i = 1 to 6;
    _x[i] = d_st[i,j];
    x = i;
    y = j;
    z = d_st[i,j];
    output long;
  end;
  output wide;
end;

stop;
run;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.