Re: Dataset transform #3

  • Follow


On 10/6/06, Raj G <rajasekhargo@yahoo.com> wrote:
........
If there is any other solution, that is also welcome (like
multidimensional arrays?).
....................

Raj,

Your data shows that variables, date and num1-num3, forms a 3 by 3 matrix
and that you want these 9 elements be presented as columns in the required
Output. I giving a restricted solution using  array but  can be generalized
if you work on it further.

Muthia Kachirayan



data a;
input id $ char1. date n1 n2 n3;
cards;
A   1     3      5      4
B   1     8      3      2
C   1     2      6      7
A   2     4      8      9
B   2     9      0      1
C   2     0      2      3
A   3     2      3      4
B   3     8      6      7
C   3     6      4      5
;
run;

proc sort data = a;
by id;
run;

data b(drop=date p n1-n3);

array k[3,3] _temporary_;

   do until(last.id);
      set a;
      by id;
      p + 1;
      k[1,p] = n1;
      k[2,p] = n2;
      k[3,p] = n3;

   end;

   n1_1 = k[1,1];
   n1_2 = k[1,2];
   n1_3 = k[1,3];
   n2_1 = k[2,1];
   n2_2 = k[2,2];
   n2_3 = k[2,3];
   n3_1 = k[3,1];
   n3_2 = k[3,2];
   n3_3 = k[3,3];
   output;

   p = 0;

run;
proc print data = b;
run;
0
Reply muthia.kachirayan (702) 10/6/2006 7:02:51 PM


0 Replies
32 Views

(page loaded in 6.106 seconds)


Reply: