You basically need to read the XLSX file twice. The first read will get the data in the first two rows and then the second read can skip those rows. You can then use the data from the first two rows to understand how to split the data into individual datasets.
First let's make a test XLSX file.
data sample;
input (x1-x9) (:$32.);
cards;
ds1 ds1 ds1 ds2 ds2 ds2 ds3 ds3 ds3
id gender name department department_name employees name category division
1 e q a w 23 q t oi
2 e q a x 24 q y uy
;
proc export data=sample dbms=xlsx file="&path\sample.xlsx" replace ;
putnames=no;
run;
Now let's read the whole thing in without names and get just the first two rows transposed so we can see how many columns there are.
proc import datafile="&path\sample.xlsx" dbms=xlsx
out=raw replace ;
getnames=no;
run;
proc transpose data=raw(obs=2) out=names ;
var _all_;
run;
Then we can use the number of rows and number of columns to generate a RANGE to use to read the real data. This is important as it should allow the numeric columns to come over as numeric variables since IMPORT will not be trying to include the column names in the data.
data _null_;
set names (keep=_name_) point=ncols nobs=ncols;
set raw (drop=_all_) nobs=nrows;
call symputx('range',cats('$A3:',_name_,nrows));
stop;
run;
%put &=range;
proc import datafile="&path\sample.xlsx" dbms=xlsx
out=values replace ;
range="&range";
getnames=no;
run;
Now we can use the information on the names to generate code to split the big dataset into little datasets. It looked like you wanted to keep the first column on all of the datasets so let's include that also.
filename code temp;
data _null_;
file code;
if _n_=1 then set names(keep=_name_ col2 rename=(_name_=idcol col2=idvar));
do until (last.col1);
set names ;
by col1 notsorted ;
if first.col1 then put 'data ' col1 ';' / ' set values(keep=' idcol _name_ '--' @;
if last.col1 then put _name_ ');' / ' rename ' idcol '=' idvar ';' ;
end;
put ' rename';
do until (last.col1);
set names ;
by col1 notsorted ;
put ' ' _name_ '=' col2 ;
end;
put ' ;' / 'run;' ;
run;
%include code / source2;