请选择 进入手机版 | 继续访问电脑版
楼主: zhaoping603
15751 11

[原创博文] 求把excel中多个sheet导入SAS,多个sheet [推广有奖]

  • 0关注
  • 0粉丝

本科生

39%

还不是VIP/贵宾

-

威望
0
论坛币
261 个
通用积分
0
学术水平
11 点
热心指数
13 点
信用等级
9 点
经验
338 点
帖子
74
精华
0
在线时间
83 小时
注册时间
2011-4-7
最后登录
2017-3-13

zhaoping603 发表于 2011-6-21 10:13:06 |显示全部楼层 |坛友微信交流群

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
如题,一个sheet的话 RANGE="Sheet1$";就可以了,但要是有多个呢,怎么改可以一下子都导入到一个SAS数据集中。
二维码

扫码加我 拉你入群

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

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

关键词:sheet EXCEL exce xcel SHE excel

回帖推荐

yugao1986 发表于4楼  查看完整内容

libname xlsfile excel 'c:\normal_ranges.xls';/*excel指定引擎读取xls格式文件,xlsfile指定excel库*/ proc contents data=xlsfile._all_; run; proc print data=xlsfile.'normal_anges$'n;/*明确输出文件的工作表*/ run;
已有 1 人评分经验 论坛币 收起 理由
liuzhenzhu + 10 + 3 鼓励积极发帖讨论

总评分: 经验 + 10  论坛币 + 3   查看全部评分

本帖被以下文库推荐

yunzhonghai 发表于 2011-6-21 10:22:37 |显示全部楼层 |坛友微信交流群
发帖同求。

使用道具

honghejing 发表于 2011-6-21 10:37:37 |显示全部楼层 |坛友微信交流群
用个macro做呗

使用道具

yugao1986 发表于 2011-6-21 11:12:15 |显示全部楼层 |坛友微信交流群
libname xlsfile excel 'c:\normal_ranges.xls';/*excel指定引擎读取xls格式文件,xlsfile指定excel库*/

proc contents

    data=xlsfile._all_;

run;

proc print

     data=xlsfile.'normal_anges$'n;/*明确输出文件的工作表*/

run;
已有 2 人评分经验 论坛币 学术水平 热心指数 收起 理由
bakoll + 3 + 3 精彩帖子
醉_清风 + 1 + 1 精彩帖子

总评分: 经验 + 3  论坛币 + 3  学术水平 + 1  热心指数 + 1   查看全部评分

三人行必有我师

使用道具

正午 发表于 2013-5-21 11:37:19 |显示全部楼层 |坛友微信交流群
谁知道了也告诉我一声啊

使用道具

geniusv 发表于 2013-5-21 20:39:36 |显示全部楼层 |坛友微信交流群
其实以前我碰过类似的情况,一个excel里面50张表,结构一样,需要合并成一个dataset,我最后的方法是vba……

使用道具

spssone 发表于 2013-5-25 17:58:07 |显示全部楼层 |坛友微信交流群
可以用宏写的

使用道具

是风啊 发表于 2013-5-25 22:21:19 |显示全部楼层 |坛友微信交流群
嘿嘿  刚才刚遇到这个问题,正好学习一下,哈哈

使用道具

Bridgenc 发表于 2013-5-25 23:15:09 |显示全部楼层 |坛友微信交流群
%macro xlread;
/**Assign a libname for excel sheet*/
LIBNAME XLSLIB "C:\NESUG-2011\Metabolite.xls" access=readonly;
/***PART1 OF THE PROGRAM USE PROC SQL TO READ THE SHEET NAMES IN THE EXCEL SHEET
SPECIFIED BY THE LIBNAME STATMENT ABOVE****/
/**creating macro variables for the sheet**/
proc sql noprint;
/***Get total Number of Sheets***/
select count(distinct(MEMNAME)) into: tot
from sashelp.vtable
where LIBNAME ='XLSLIB' AND INDEX(MEMNAME,'General')=0;
/**Get the sheet names without $ in to macro variables***/
select distinct(compress(MEMNAME,"',$")) into: s1 - :s%trim(%left(&tot))
from sashelp.vtable
where LIBNAME ='XLSLIB' AND INDEX (MEMNAME,'General')=0;
/**Get the sheet names with $ in to macro variables***/
select distinct(MEMNAME) into: v1 - :v%trim (%left(&tot))
from sashelp.vtable
where LIBNAME ='XLSLIB' AND INDEX (MEMNAME,'General')=0;
/**GET NAMES WITH OUT THE DELIMETERS***/
select distinct(compress(MEMNAME,"',$,-")) into: c1 - :c%trim(%left(&tot))
from sashelp.vtable
where LIBNAME ='XLSLIB' AND INDEX(MEMNAME,'General')=0;
Quit;


/***PART2 THE ABOVE MACRO VARIABLE TOT IS USE TO RUN A DO LOOP SO THAT WE HAVE TO
CREATE NAMES OF THE VARIABLES****/
%do i=1 %to &tot;
/*Create macro variables to store names of variables for reach dataset*/
proc sql noprint;
select COUNT(distinct(NAME)) into: T
from sashelp.vcolumn
where LIBNAME ='XLSLIB' AND MEMNAME="&&v&i." and SUBSTR(NAME,1,1)^='F';
select distinct(NAME) into: O1 - :O%trim(%left(&T))
from sashelp.vcolumn
where LIBNAME ='XLSLIB' AND MEMNAME="&&v&i." and SUBSTR(NAME,1,1)^='F';
QUIT;
/**set the datasets**/
data &&c&i.;
set xlslib."&&s&i.$"n;
RUN;
/**renaming the variable names to set all of them**/
PROC DATASETS LIBRARY=WORK;
MODIFY &&C&i.;
%do j=1 %to &T;
rename
&&O&j. =%sysfunc(compress("&&O&j.","',$,-,_ "));
%end;
quit;
run;
%end;
/***SAS 9.2 Code***/
data final;
set data1 - data&tot.:
run;
/***THIS MACRO WAS USED FROM SAS.COM WEBSITE
http://support.sas.com/kb/26/010.html***/
/**Code from SAS.COM***/
%macro names(prefix,maxnum);
%do i=1 %to &maxnum;
&prefix&i
%end;;
%mend names;

/***SAS 9.1.3 Code**/
data final;
set %names(Source,&tot);
run;
%mend;
%xlread;

使用道具

skylandocean 在职认证  发表于 2015-10-16 15:44:30 |显示全部楼层 |坛友微信交流群
Bridgenc 发表于 2013-5-25 23:15
%macro xlread;
/**Assign a libname for excel sheet*/
LIBNAME XLSLIB "C:\NESUG-2011\Metabolite.xls" ...
这么复杂啊?

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-18 22:06