|
楼主

楼主 |
发表于 2012-6-13 23:25:11
|
只看该作者
excel中的所有sheet导入sas
遇到一个问题请大家帮忙,在一个excel薄中有很多sheet,每个sheet的名字都没有规律,想把它导入sas,
[url:2skz1h5f]http://blog.sina.com.cn/s/blog_7f8b10ef01013py6.html[/url:2skz1h5f]发现了下面的一段代码,
[code:2skz1h5f]
%let dir=C:\sasCode;
%macro ReadXls (name);
libname excellib excel "&dir.\&name";
proc sql noprint;
create table sheetname as
select tranwrd(memname, "''", "'" ) as sheetname
from sashelp.vstabvw
where libname= "EXCELLIB";
select count(DISTINCT sheetname) into :number
from sheetname;
select DISTINCT sheetname into :sheet1 - :sheet%left(&number)
from sheetname;
quit;
libname excellib clear;
%do i=1 %to &cnt_sht;
proc import datafile= "&dir.\&name"
out=sheet&i replace;
sheet= "&&sheet&i";
getnames=yes;
mixed=yes;
run;
proc append base=master data=sheet&i force;
run;
%end ;
%mend ReadXls;
%ReadXls (abc.xls)
[/code:2skz1h5f]
试了上述代码后,产生如下错误
NOTE: Libref EXCELLIB was successfully assigned as follows:
Engine: EXCEL
Physical Name: C:\sasCode\abc.xls
NOTE: The query as specified involves ordering by an item that doesn't appear in its SELECT clause.
NOTE: Table WORK.SHEETNAME created, with 0 rows and 1 columns.
WARNING: INTO Clause :sheet1 thru :sheet0 does not specify a valid sequence of macro variables.
NOTE: No rows were selected.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.29 seconds
cpu time 0.03 seconds
NOTE: Libref EXCELLIB has been deassigned.
WARNING: Apparent symbolic reference CNT_SHT not resolved.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition
was: &cnt_sht
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro READXLS will stop executing.
阅读代码后,感觉是下面一段有问题
[code:2skz1h5f]
libname excellib excel "&dir.\&name";
proc sql noprint;
create table sheetname as
select tranwrd(memname, "''", "'" ) as sheetname
from sashelp.vstabvw
where libname= "EXCELLIB";
[/code:2skz1h5f]
其实,我对
from sashelp.vstabvw
where libname= "EXCELLIB";
不了解,感觉很可能是不对的,所以向大家请教,恳请您们帮忙。
如果有别的导入方式,请告诉我一下,非常感谢。 |
|