楼主: Imasasor
9388 15

export 导出的excel sheet名字包含特殊字符 [推广有奖]

  • 1关注
  • 64粉丝

VIP

学科带头人

34%

还不是VIP/贵宾

-

TA的文库  其他...

超哥喜欢的文章

威望
1
论坛币
47033 个
通用积分
3.1376
学术水平
238 点
热心指数
246 点
信用等级
231 点
经验
36380 点
帖子
866
精华
3
在线时间
2234 小时
注册时间
2012-7-4
最后登录
2023-9-20

初级学术勋章 初级热心勋章 初级信用勋章 中级热心勋章 中级学术勋章

1000论坛币
各位高手

proc export data=sashelp.class outfile="D:\class.xls";
sheet="班级-成绩@";
run;


导出的excel sheet名字中,短杆和@都被转换成了下划线,怎么保证特殊字符不被转换成下划线
比如我这里的-和@

急,谢谢各位

最佳答案

zhengbo8 查看完整内容

用DDE间接实现的,要是不弹出Excel窗口就更好。 注:运行环境为 Office2003 + SAS 9.1.3 求币。
关键词:export xport EXCEL sheet exce export excel
欢迎加入亚太地区第一R&Python数据挖掘群: 251548215;
沙发
zhengbo8 发表于 2013-12-6 14:11:35 |只看作者 |坛友微信交流群
用DDE间接实现的,要是不弹出Excel窗口就更好。

  1. options noxwait noxsync;

  2. X 'del "D:\class.xls"';  

  3. proc export data=sashelp.class outfile="D:\class.xls";
  4.         sheet="sheet1";
  5. run;

  6. X '"D:\class.xls"';  

  7. data _null_;

  8.         z=sleep(1);

  9. run;

  10. filename cmds dde 'excel|system';

  11. data _null_;

  12.         file cmds;
  13.         put '[workbook.insert(3)]';

  14. run;

  15. filename xlmacro dde 'excel|macro1!r1c1:r5c1' notab;

  16. data _null_;

  17.         file xlmacro;
  18.                 put '=workbook.name("sheet1","班级-成绩@")';
  19.                 put '=halt(true)';
  20.                 put '!dde_flush';
  21.         file cmds;
  22.                 put '[run("macro1!r1c1")]';
  23.                 put '[error(false)]';
  24.                 put '[workbook.delete("macro1")]';
  25.                 put '[save()]';
  26.                 put '[quit()]';
  27.                 z=sleep(1);

  28. run;
复制代码

注:运行环境为 Office2003 + SAS 9.1.3

求币。

已有 2 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
webgu + 100 + 100 + 5 + 5 + 5 牛!
Imasasor + 100 + 100 + 5 + 5 + 4 分析的有道理

总评分: 经验 + 200  论坛币 + 200  学术水平 + 10  热心指数 + 10  信用等级 + 9   查看全部评分

使用道具

藤椅
slimdell 发表于 2013-12-6 15:19:38 |只看作者 |坛友微信交流群
SAS 官网上有相似的问题可以参考
http://support.sas.com/kb/33/255.html

Problem Note 33255: Dashes mistranslated to underscores when using the IMPORT and EXPORT procedures in sheetnames
   

Dash characters are mistranslated to underscores when using the SHEET= option with the IMPORT and EXPORT procedure. In this example:

proc export data = sashelp.class
dbms = excel
file = "j:\mydata\testout.xls"
replace;
sheet = 'AE-MHX';
run;
The sheet created in EXCEL is named AE_MHX instead of AE-MHX.

The IMPORT procedure works in a similar way. In this example the IMPORT procedure will attempt to import a sheet with a dash character.

proc import file = "j:\mydata\testout.xls"
dbms = excel
out = test
replace;
sheet = 'AE-MHX';
run;
However the IMPORT procedure will actually look for AE_MHX as the sheetname.

To circumvent the problem, avoid dashes in your sheetname when creating the Excel file and rename the dash character to an underscore character when importing the file.


知乎专栏/微信公号同名:煮酒烹茶读书

使用道具

板凳
Imasasor 发表于 2013-12-6 16:09:56 |只看作者 |坛友微信交流群
slimdell 发表于 2013-12-6 15:19
SAS 官网上有相似的问题可以参考
http://support.sas.com/kb/33/255.html
但是他没有回答问题啊,只是提出了问题
欢迎加入亚太地区第一R&Python数据挖掘群: 251548215;

使用道具

报纸
webgu 发表于 2013-12-6 16:33:01 |只看作者 |坛友微信交流群
此题无解。
SAS资源
1. SAS 微信:StatsThinking
2. SAS QQ群:348941365

使用道具

地板
zhengbo8 发表于 2013-12-6 16:57:02 |只看作者 |坛友微信交流群
嗯,回去试试。

使用道具

7
playmore 发表于 2013-12-6 17:19:27 |只看作者 |坛友微信交流群
看了链接的网页,人家都这么说了

To circumvent the problem, avoid dashes in your sheetname when creating the Excel file and rename the dash character to an underscore character when importing the file.

那估计可能一定是无解了

要不就用DDE试试,不用proc import和export
playmore邀请您访问ChinaTeX论坛!!!进入ChinaTeX论坛

使用道具

8
bobguy 发表于 2013-12-7 08:55:45 |只看作者 |坛友微信交流群
You can use libname engine to work it out easily. Here is an example.

10   libname S EXCEL 'c:\temp\book0.xlsx' ;
NOTE: Libref S was successfully assigned as follows:
      Engine:        EXCEL
      Physical Name: c:\temp\book0.xlsx
11
12   data s.'tmp-35 1* () @'n;
13     set sashelp.class;
14   run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set S.'tmp-35 1* () @'n has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


15
16   libname S clear;
NOTE: Libref S has been deassigned.

使用道具

9
Imasasor 发表于 2013-12-7 10:05:47 |只看作者 |坛友微信交流群
bobguy 发表于 2013-12-7 08:55
You can use libname engine to work it out easily. Here is an example.

10   libname S EXCEL 'c:\te ...
表示未能成功啊??
55   libname S EXCEL 'd:\book1.xls' ;
NOTE: 已成功分配逻辑库引用名 S,如下所示:
       引擎:        EXCEL
       物理名: d:\book1.xls
56   options validvarname=any;
57
58
59    data s.'tmp-35 1* () @'n;
60      set sashelp.class;
61    run;

NOTE: SAS 变量标签、格式和长度并未写入 DBMS 表。
NOTE: 有 19 个从数据集 SASHELP.CLASS 读取的观测。
NOTE: 数据集 S.'tmp-35 1* () @'n 有 19 个观测和 5 个变量。
NOTE: “DATA 语句”所用时间(总处理时间):
      实际时间          0.04 秒
      CPU 时间          0.01 秒


62
63    libname s clear;
NOTE: 已取消对逻辑库引用名 S 的分配。
upload.jpg
欢迎加入亚太地区第一R&Python数据挖掘群: 251548215;

使用道具

10
zhengbo8 发表于 2013-12-7 10:07:55 |只看作者 |坛友微信交流群
bobguy 发表于 2013-12-7 08:55
You can use libname engine to work it out easily. Here is an example.

10   libname S EXCEL 'c:\te ...
表格中表名还是被SAS转义成-。

使用道具

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

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

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

GMT+8, 2024-5-1 01:16