Hello,
You can try this code:
* Create sample data;
data UNORDERED(drop=i j);
length
A1-A50
C1-C50
E1-E50 8;
array cols {*} A1-A50 C1-C50 E1-E50;
do i=1 to 1000;
do j=1 to 150;
cols[j]=rand('UNIFORM');
end;
output;
end;
run;
* Using the COLUMNS dictionary table to get all the columns and sort them as needed;
proc sql noprint;
create table COLUMNS as
select
name,
substr(name,1,1) as Prefix length=1,
input(substr(name, 2), 2.) as Suffix
from
DICTIONARY.COLUMNS
where
libname='WORK' and memname='UNORDERED'
order by
3,2;
quit;
* Generating proc sql code to re-arrange the columns;
filename sascode temp;
data _null_;
set COLUMNS end=last;
file sascode;
if _n_=1 then do;
put 'proc sql noprint;';
put 'create table ORDERED as ';
put 'select ';
end;
put name @;
if ^last then put ',';
if last then do;
put 'from UNORDERED;';
put 'quit;';
end;
run;
%include sascode;
filename sascode clear;
Thanks,
Hagay
... View more