/*在下面的代码中增加了WINWORD退出机制*/
/*使用前建议重启一下PC*/
options noxwait noxsync;
%macro word2sas(in=, out=);
/*%let in=&fname;*/
/*%let out=example1;*/
%let rc=%sysfunc(system(start winword));
data _null_;
null= sleep(5);
run;
filename word DDE 'Winword|System';
data _null_;
file word;
put '[FileOpen.Name = "' "&in" '"]';
put "[EditSelectAll]";
put "[EditCopy]";
put '[FileClose]';
put '[AppMinimize]';
run;
%let rc=%sysfunc(system(start excel));
data _null_;
null= sleep(5);
run;
filename excel dde 'excel|system';
data _null_;
file excel;
put '[error(false)]';
put '[paste]';
put '[SAVE.AS("Example.xls")]';
put '[Select.Last.Cell()]';
put '[Copy]';
put '[quit]';
run;
%let rc=%sysfunc(system(taskkill/im winword.exe));
proc import datafile= "Example.xls" out=&out dbms=xls replace;
getnames=no;
mixed=yes;
run;
filename fd "Example.xls";
%let rc=%sysfunc(fdelete(fd));
filename _all_ clear;
%mend word2sas;
/*%word2sas(in=data1.doc, out=example1);*/
%let dirname = D:\Docs;
x "cd &dirname";
filename dirlist pipe "dir /B &dirname\*.doc";
data dirlist ;
length fname $256;
infile dirlist length=reclen ;
input fname $varying256. reclen ;
run;
data _null_;
set dirlist end=last;
if last then call symput('nobs',_n_);
run;
%macro CAL;
%let number=1;
%do %while(&number le &nobs);
data _null_;
set dirlist(firstobs=&number obs=&number);
call symput("fname",trim(fname));
run;
%word2sas(in=&fname, out=example1);
proc datasets library=work nolist;
append base=all_data data=example1;
delete example1;
quit;
%let number=%eval(&number+1);
%end;
%mend ;
%CAL;



雷达卡







京公网安备 11010802022788号







