使用工作表名称将数据输出到 Excel 包含空格 [英] output data to excel with sheet name contains space
问题描述
data _null_;
call symputx('ts','a b');
run;
proc export data=have
outfile='pathfile.xlsx';
sheet="&ts.";
run;
但这会创建一个名为a_b
的工作表(原来的空格被替换为_
.
But this will create a sheet named a_b
(the original space is replaced by _
.
怎么会这样?
推荐答案
这与 SAS 的 proc export
中的工作方式有关.它在幕后所做的是创建一个 libname
,然后创建一个数据集.在正常 (validmemname=compat
) 规则下,数据集名称中可能没有空格.有一个选项 (validmemname=extend
) 告诉 SAS 允许空格(然后您使用 named literal
访问,即 "ab"n
(n 告诉 SAS 这是一个名称),但似乎 proc export(和 libname 本身)不听.
That's related to how things work in SAS's proc export
. What it's doing behind the scenes is creating a libname
, and then creating a dataset. Under normal (validmemname=compat
) rules, you may not have spaces in dataset names. There is an option (validmemname=extend
) to tell SAS to allow spaces (Which you then use a named literal
to access, namely, "a b"n
(the n tells SAS it's a name), but it seems proc export (and libname itself) doesn't listen to that.
但是,目前有一种解决方法:如果您使用的是 SAS 9.4 TS1M1 或更高版本,则可以在导出中使用 dbms=xlsx
.这使用了与默认 excel
(使用 Microsoft 的 JET 引擎)不同的引擎,并且它很容易允许空格.
However, in the present day, there is a workaround for this: You can use dbms=xlsx
in the export if you are on SAS 9.4 TS1M1 or later. This uses a different engine than the default excel
(which uses Microsoft's JET engine), and it permits spaces easily.
这篇关于使用工作表名称将数据输出到 Excel 包含空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!