Using value of an array to define variable list of another array

Reply
Contributor
Posts: 60

Using value of an array to define variable list of another array

Hi All,

I have a scenario where i need to use the values of an array to be variable list for another array.

something like;

array test(3) $ ('one', 'two', 'three');

do i=1 to 3;

array test1(*) test(i)0 - test(i)100;

end;

In the above code snippet, i would like to do something like replacing test(i) with value one so the array definition for test1 would look like, array test1(*) one0-one100 for the first iteration of do loop; and for the second iteration of do loop array definition should  look like, array test1(*) two0-two100 and so forth.

Is this possible? or is there any other way to tackle such scenario efficiently?

Thanks,

Saravanan

Respected Advisor
Posts: 3,799

Re: Using value of an array to define variable list of another array

Posted in reply to Saravanan

How about a 2 diminsonal array?

39         data _null_;
40            array a[3,5] one1-one5 two1-two5 thr1-thr5;
41            do j = 1 to dim1(a);
42               do i = 1 to dim2(a);
43                  x + 1;
44                  a[j,i] = x;
45                  end;
46               end;
47            put _all_;
48            run;

one1=
1 one2=2 one3=3 one4=4 one5=5 two1=6 two2=7 two3=8 two4=9 two5=10 thr1=11 thr2=12 thr3=13 thr4=14 thr5=15 j=4 i=6 x=15
_ERROR_=
0 _N_=1
Contributor
Posts: 60

Re: Using value of an array to define variable list of another array

Posted in reply to data_null__

Thank you so much. This is a very good alternative.

Saravanan

Ask a Question
Discussion stats
  • 2 replies
  • 203 views
  • 5 likes
  • 2 in conversation