Not sure why your method is not working, but for now you can use scan
function to extract the elements, code is pretty much self explanatory, let me know if you don't get it
data _null_;
array temp{*} &varname;
do i=1 to dim(temp);
temp_1 = scan("&varname.",i);
put temp_1;
end;
second_element=scan("&varname.",2);
put second_element=;
run;
EDIT:
Your method
array temp{*} &varname
which eventually translates to
array temp{*} DEPTHEAD JOB1 LEVEL1 LEVEL2 LEVEL3 LEVEL4 LEVEL5 N;
is not working because by doing that array variable names are defined and not the values are initialized
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000201956.htm
Look for this statement
array simple{3} red green yellow;
If you want to do it your way then you have to do something like this
data _null_;
array tempar{8} $ tempar1-tempar8 ("DEPTHEAD" "JOB1" "LEVEL1" "LEVEL2" "LEVEL3" "LEVEL4" "LEVEL5" "N");
do i=1 to dim(tempar);
put tempar(i)=;
end;
run;
Notice first I have defined the individual elements of the array - tempar1-tempar8
and have defined it char
using $
and then I have intialized the values that too in quotes.
EDIT2:
Tested
If you absolutely can't deviate from your approach, below is the code(which is less efficient than what I have suggested above)
proc datasets library=sashelp;
contents
data=company
out=work.var_names;
quit;
run;
proc sql noprint;
select quote(compress(name)) into: varname separated by ' '
from var_names;
select count(name) into: Numofelements from var_names;
quit;
%put %quote(&varname.);
%put &Numofelements;
data _null_;
array tempar{%sysfunc(compress(&Numofelements.))} $ tempar1-tempar%sysfunc(compress(&Numofelements.)) (%quote(&varname.));
do i=1 to dim(tempar);
put tempar(i)=;
end;
run;