全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1530 0
2011-09-12
options noxwait;
%macro ReadXls (dir=);
%sysexec cd &dir; %sysexec dir *.xls /b/o:n > flist.txt;
data _indexfile;
length filen $200;
infile "&dir./flist.txt";
input filen $;
run;
proc sql noprint;
select count(filen) into :cntfile from _indexfile;
%if &cntfile>=1 %then %do;
select filen into :filen1-:filen%left(&cntfile)
from _indexfile;
%end;
quit;
%do i=1 %to &cntfile;
libname excellib excel "&dir.\&&filen&i";
proc sql noprint;
create table sheetname as
select tranwrd(memname, "''", "'") as sheetname
from sashelp.vstabvw
where libname="EXCELLIB";
select count(DISTINCT sheetname) into :cnt_sht
from sheetname;
select DISTINCT sheetname into :sheet1 - :sheet%left(&cnt_sht)
from sheetname;
quit;
%do j=1 %to &cnt_sht;
proc import datafile="&dir.\&&filen&i"
out=sheet&j replace;
sheet="&&sheet&j";
getnames=yes;
mixed=yes;
run;
data sheet&j;
length _excelfilename $100 _sheetname $32;
set sheet&j;
_excelfilename="&&filen&z";
_sheetname="&&sheet&j";
run;
proc append base=master data=sheet&j force;
run;
%end;
libname excellib clear;
%end;
%mend ReadXls;
%readxls (dir=c:\my documents\excel files)


用上面的程序导入数据,结果发现数据被导入两次,问题出在哪里?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群