首页 > 解决方案 > 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。

标签: sas

解决方案


如果您不提供任何输出,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 ....

推荐阅读