You can capture the number of elements in a macro variable and use that value to set the new array dimension:
/* Make some data to play with */
data cus1;
array Visit{15};
do obs=1 to 100;
do i=1 to dim(Visit);
Visit{i}=ranuni(1);
if Visit{i} > .8 then Visit{i}=.;
end;
Misses=NMISS(of Visit{*});
output;
end;
drop obs i;
run;
/* Find out how many elements, store in macro variable Num */
data _null_;
set cus1;
array V{*} visit:;
call symputx('Num',dim(V));
stop;
run;
%PUT NOTE: There were &Num elements in the V array;
/* Now create the new array using &Num as the array size */
data cus2;
set cus1;
array V{*} visit:;
array Visit_{&Num} ;
do i = 1 to dim(V);
Visit_{i} = V{i} + 1;
end;
run;
Or, you could query the dictionary tables to find out how many varibles names start with 'visit' in the cus1 data set:
proc sql noprint;
select count(*)
into :Num
from dictionary.columns
where LIBNAME ='WORK'
and MEMNAME='CUS1'
and lowcase (Name) like 'visit%'
;
quit;