An array statement does not create a new data structure. It creates a name by which other variables can be referenced.
The name of the underlying variable is returned by the vnamefunction.
data _null_;
array ary[3] foo bar baz;
foo = 42;
bar = 999;
baz = 7;
do i = 1 to dim(ary);
ary[i] = ary[i]+i;
put ary[i]=;
/* The loop prints:
foo=43
bar=1001
baz=10
NOTE although the put statement uses ary[i], the
actual printed variable name are the underlying
foo, bar and baz.
*/
end;
put "Changed value of foo = " foo;
put "Changed value of bar = " bar;
put "Changed value of baz = " baz;
/*
The above puts print:
Changed value of foo = 43
Changed value of bar = 1001
Changed value of baz = 10
Again, the assignement to ary[i] in the do loop have
changed the underlying variables.
*/
run;
data tq84_data;
/* Set the length of each element of the array
to 20 characters: */
array num{*} $20 num_1-num_10;
input num_1-num_10;
datalines;
one two three four five six seven eight nine ten
eins zwei drei vier fünf sechs sieben acht neun zehn
un deux trois quattre cinque six sept huit neuf dix
run;
proc print
data=tq84_data;
run;
data _null_;
var_foo = 'Foo';
var_bar = 'Bar';
var_baz = 'Baz';
/* Variables with a common prefix (here: "var_") can
be referenced with a colon: */
array ary{*} var_:;
do i=1 to dim(ary);
put 'ary ' i ': ' ary[i];
end;
/* The put statement puts:
ary 1 : Foo
ary 2 : Bar
ary 3 : Baz
*/
run;
data _null_;
foo = 42;
bar = 999;
baz = 17;
/* Usually, the first index is 1. In the following
statement, it's changed to 0 */
array ary{0: 2} foo bar baz;
do i = 0 to dim(ary)-1; /* Note the dim() - 1 */
put i ': ' ary{i};
end;
run;