The data set flip-flop using TRANSPOSE is a useful technique. However, it will cause all variables to be converted to character if any variables in the VAR list are character. The conversion to character can be a useful but that is another subject.
You can use DICTIONARY.COLUMNS to produce a alphabetical list of variables. Although there will be problems with that if any of the variables are members of an enumerated variable lists. For example B1-B10 will come out B1 B10 B2 and so on. PROC CONTENTS produces the correct ordering.
[pre]
data fin;
input w a x z p;
B5=1;
array b[10];
cards;
1 2 3 5 6
;;;;
run;
proc sql noprint;
select name into :alphaList separated by ' '
from dictionary.columns
where libname eq 'WORK' and memname eq 'FIN'
order by 1
;
quit;
run;
/* use ALPHALIST as you see fit */
%put NOTE: ALPHALIST=&alphalist;
/* correct order for alphalist with enumerated variables list*/
proc contents noprint order=ignorecase out=alphalist(keep=name);
run;
proc sql noprint;
select name into :alphaList separated by ' '
from alphalist
;
quit;
run;
/* use ALPHALIST as you see fit */
%put NOTE: ALPHALIST=&alphalist;
[/pre]