sas - SAS:如果没有数据,ODS Excel 会锁定文件
问题描述
我注意到,每当我尝试在 ODS Excel 中运行 PROC REPORT 并且没有数据时,它永远不会完成对文件的写入,只会卡住。文件保持锁定状态。
为什么会这样以及如何解决?我事先不知道我的报告是否会有任何数据。
这是示例代码:
data person;
input name $ dept $;
datalines;
;
GOPTIONS RESET=ALL;
ODS Excel FILE = "C:\Users\jloktie\Desktop\test1.xlsx" STYLE = CSROD
options(embedded_titles='yes' sheet_interval='none' autofilter= 'all'
Absolute_Column_Width = '10') ;
proc report data = person nowd HEADLINE HEADSKIP
style (report) = {background = white font_face = "Verdana" font_size = 8pt just=LEFT }
style (column) = {background = white font_face = "Verdana" font_size = 8pt just=LEFT}
style (header) = {foreground = white font_face="Verdana" font_size = 10pt just=LEFT background = cx4d4d4d} ;
columns name;
define name / "Name";
run;
ODS _ALL_ CLOSE;
这是日志所说的:
29349 data person;
29350 input name $ dept $;
29351 datalines;
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.PERSON has 0 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.01 seconds
29353 ;
29354
29355
29356 GOPTIONS RESET=ALL;
29357 ODS Excel FILE = "C:\Users\jloktie\Desktop\test1.xlsx" STYLE = CSROD
29358
29359 options(embedded_titles='yes' sheet_interval='none' autofilter= 'all'
29360 Absolute_Column_Width = '10') ;
29361
29362 proc report data = person nowd HEADLINE HEADSKIP
29363
29364 style (report) = {background = white font_face = "Verdana" font_size = 8pt just=LEFT }
29365 style (column) = {background = white font_face = "Verdana" font_size = 8pt just=LEFT}
29366 style (header) = {foreground = white font_face="Verdana" font_size = 10pt just=LEFT background
29366! = cx4d4d4d} ;
29367
29368
29369 columns name;
29370
29371 define name / "Name";
29372
29373 run;
NOTE: No observations in data set WORK.PERSON.
NOTE: No observations in input data set.
NOTE: PROCEDURE REPORT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
29374
29375 ODS _ALL_ CLOSE;
NOTE: Writing EXCEL file: C:\Users\jloktie\Desktop\test1.xlsx
我正在使用 SAS 9.4 TS Level 1M4。
解决方案
如果您不提供任何输出,ODS EXCEL 不会生成有效的 XLSX 文件。因此,要么添加一些其他输出,要么在没有输出时跳过运行 ODS 语句。
始终具有输出的一种方法是确保数据集始终具有至少一个观察值。
data for_report ;
if _n_=1 and eof then output;
set person end=eof;
output;
end;
proc report data=for_report ....
推荐阅读
- c# - C# - “动态”DataGridView
- css - css 在 github 页面上不起作用
- neo4j - 如何在 Neo4j 中存储带有有序孩子的树?如何在 Cypher 中遍历这样的结构?
- fortran - 与派生类型的组件相关的分段错误
- c# - c#out参数,为什么我给我的变量赋值了,还是不能返回?
- powerbi - 如何在powerquery中用null替换文本?
- node.js - Node.js 快速请求 - 在请求错误时淡入和淡出引导模式
- mysql - MySQL - 如何在 ISO 8601 中选择现有的日期时间值
- c# - C# sharepoint 如何从特定视图中检索列表项
- c# - 如何根据数字格式将十进制和十六进制字符串解析为int