楼主: dingyi0011
1555 0

[原创博文] 关于批量导入文件 [推广有奖]

  • 0关注
  • 0粉丝

大专生

70%

还不是VIP/贵宾

-

威望
0
论坛币
88 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
379 点
帖子
23
精华
0
在线时间
74 小时
注册时间
2007-3-16
最后登录
2019-5-5

楼主
dingyi0011 发表于 2011-9-12 07:46:04 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
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)


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

扫码加我 拉你入群

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

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

关键词:导入文件 批量导入 documents Distinct filename

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-1 02:56