0

I want to create an array which stores the names of variables. Then index into the array and pass to a function. So far I have the following:

%let variables = cat dog lion sheep;

data _null_;
  array a_vars[*] &variables;
  do i = 1 to dim(a_vars);
    some_function(a_vars[i],i);
  end;
run;

I'm running into a problem with assigning the variables to the array and then indexing the array in the function to do: some_function(cat, 1) or some_function(dog,2) etc.

Josh
  • 3,231
  • 8
  • 37
  • 58

1 Answers1

0

I'm not sure I understand exactly what you want to do. As mentioned you can use VNAME to find the name of the ith array element. Is that really what you need?

26         data _null_;
27            array a_vars[*] &variables;
28            length name $32;
29            do i = 1 to dim(a_vars);
30               name = vname(a_vars[i]);
31               put (i name) (=);
32               end;
33            run;

i=1 name=cat
i=2 name=dog
i=3 name=lion
i=4 name=sheep
data _null_
  • 8,534
  • 12
  • 14