@JacquesR : There are a bunch of questions you haven't addressed. Off the top of my head: * Do all the workbooks have similar structure? * Are the worksheet names valid SAS dataset names? * Are the worksheet names repeated across workbooks? If so, how do you handle duplicate names, so datasets don't get overwritten? * Otherwise, what output dataset naming pattern do you want? * Do all the worksheets have valid SAS column names in row 1? * If not, how do you intend to name the resultant SAS columns (likely named F1, F2, etc) * Will your worksheet structure ever change? For example, will AU workbooks ever have more (or less) than 5 worksheets? I'm not saying don't use macro - the below approach does use macro - but IMO your macro code is convoluted, hard to follow, and hard to maintain. Although I do admit my excel2sas macro is complex. At least I've tried to debug it thoroughly - YMMV. I'm on SAS 9.3 so I couldn't use the XLSX engine. But the attached %excel2sas macro did work in my environment. If you're on SAS 9.4, try changing the libname _XCEL_ to use the XLSX engine. I threw together a quick test, copying a few Excel workbooks into a directory. This code imported every worksheet from every workbook in the directory, naming the SAS dataset based on the worksheet name. Perhaps you can run with this, after gaining an understanding of the macros. * get list of Excel files ;
%dirlist(
dir=\\UNC\path\to\files\Excel
,filter=ext='xlsx'
);
* macro to run for every record in dirlist ;
%macro code;
* need to strip leading and trailing spaces ;
%let fullname=%sysfunc(strip(&fullname));
%excel2sas(file=&fullname,getnames=yes);
%mend;
* run %excel2sas for every fullname ;
%loop_control(control=dirlist); From glancing at your code, I'd say you need to fiddle with the dirlist output to derive the correct worksheet names, then feed the correct name into %excel2sas. Try to derive all your metadata in the datastep, not via macro. Another option is, if the worksheet name can be "translated" by %excel2sas into a valid SAS dataset name, then post-process the import via additional code (proc datasets rename dataset) in the %code macro, after the call to %excel2sas. My advice is to get %excel2sas to 1) work in your environment, and 2) test it with a small subset of your workbooks, and 3) see if post-processing will work, 4) otherwise, CAREFULLY modify the macro. Hope this helps...
... View more