Hi.
I have another resolution.
Using command 'dir c:\temp\*.xls /s' which can display all the xls files in the temp directory and its all the sub-directory. then using FILENAME and PIPE to get the directory and filename.But each xls file must has unique name to avoid erase the dataset with same name.
[pre]
*To import multi xls files from multi sub-directory.Suppose all the sub-directory with xls files are in the 'c:\temp\';
filename _xls pipe 'dir c:\temp\*.xls /s';
data xls_file;
infile _xls length=len;
input whole $varying200. len;
retain directory;
length file_name $ 200;
if strip(whole) eq: 'c:\temp' then directory=scan(whole,1,' ');
else if scan(whole,-1,'.') eq 'xls' then do;
_name=scan(trim(whole),-1,' ');
file_name=catx('\',directory,_name);
output;
end;
keep file_name;
run;
data _null_;
set xls_file nobs=num_obs;
call symputx(cats('path',_n_),file_name);
call symputx(cats('name',_n_),scan(file_name,-2,'.\'));
call symputx('nobs',num_obs);
run;
%put _user_;
options mprint mlogic symbolgen;
%macro xls_to_csv;
%do i=1 %to &nobs;
proc import datafile="&&path&i" out=&&name&i dbms=excel replace;
getnames=yes;
mixed=yes;
run;
proc export data=&&name&i outfile="%scan(&&path&i,1,'.').csv " dbms=csv replace;run;
%end;
%mend ;
%xls_to_csv
[/pre]
Ksharp
... View more