l**********s 发帖数: 255 | 1 我可以用如下的code分别打开三个excel文件 ,但是如何同时打开它们呢?实际上我有
上百个excel文件需要打开,是否可以用同一个简短的code同时打开它们呢?多谢!
PROC IMPORT OUT= WORK.a1
DATAFILE= "h:\a1.xls"
DBMS=EXCEL REPLACE;
SHEET="sheet1";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;
PROC IMPORT OUT= WORK.a2
DATAFILE= "h:\a2.xls"
DBMS=EXCEL REPLACE;
SHEET="sheet1";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN; |
D******n 发帖数: 2836 | 2 u r reading in the data, u r not just "OPENING" it. U don't simultaneously
open all these files. I guess what u mean is how to write a macro to read in
hundreds of excel files. |
l**********s 发帖数: 255 | 3 Thanks a lot. Yes, I mean "read"---could you or anybody help me? I am trying
to use macro but still did not figure it out. This is my RA stuff, and I
need to figure it out soon or "read" the excels seperatively. |
s******r 发帖数: 1524 | 4 %macro M_test;
%do i=1 %to 100;
PROC IMPORT OUT= WORK.a&i
DATAFILE= "h:\a&i..xls"
DBMS=EXCEL REPLACE;
SHEET="sheet1";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;
%end;
%mend M_test;
%M_test;
【在 l**********s 的大作中提到】 : 我可以用如下的code分别打开三个excel文件 ,但是如何同时打开它们呢?实际上我有 : 上百个excel文件需要打开,是否可以用同一个简短的code同时打开它们呢?多谢! : PROC IMPORT OUT= WORK.a1 : DATAFILE= "h:\a1.xls" : DBMS=EXCEL REPLACE; : SHEET="sheet1"; : GETNAMES=YES; : MIXED=NO; : SCANTEXT=YES; : USEDATE=YES;
|
l**********s 发帖数: 255 | 5 多谢楼上的答复,再请问下如果每个要打开的excel文件名字没有规律可寻, 比如5个文
件依此叫做abc, abk, abj, nbc, cnn,该怎么办呢? |
c**d 发帖数: 104 | 6 Suppose you have a lot of excel files under H:\Temp
/* get excel names */
filename myxls 'dir "H:\Temp" /b' LRECL=5000;
data myfile;
infile myxls length = len;
input fname $200. len;
run;
/* save each into a macro variable */
proc sql;
select fname into :a1 - :a9999
/* do loop to input excel */
【在 l**********s 的大作中提到】 : 多谢楼上的答复,再请问下如果每个要打开的excel文件名字没有规律可寻, 比如5个文 : 件依此叫做abc, abk, abj, nbc, cnn,该怎么办呢?
|
f*****a 发帖数: 693 | 7 Try this one. Can some one give some improvement, such as change variable
file into a file which includes all the to be input file names? Thanks.
%macro openfile(file);
%let file=all you file name list with space as delimiter (no space inside
file names);
%let i=1;
%let name=%scan(&file,&i);
%do %until(not %length(&name));
proc import out=work.&name
datafile="h:\&name"
dbms=excel replace;
sheet="sheet1";
getnames=yes;
mixed=no;
scantext |
f*****a 发帖数: 693 | 8 Good one, thanks.
【在 c**d 的大作中提到】 : Suppose you have a lot of excel files under H:\Temp : /* get excel names */ : filename myxls 'dir "H:\Temp" /b' LRECL=5000; : data myfile; : infile myxls length = len; : input fname $200. len; : run; : /* save each into a macro variable */ : proc sql; : select fname into :a1 - :a9999
|
l**********s 发帖数: 255 | 9 Thanks, it works!!
【在 f*****a 的大作中提到】 : Try this one. Can some one give some improvement, such as change variable : file into a file which includes all the to be input file names? Thanks. : %macro openfile(file); : %let file=all you file name list with space as delimiter (no space inside : file names); : %let i=1; : %let name=%scan(&file,&i); : %do %until(not %length(&name)); : proc import out=work.&name : datafile="h:\&name"
|