美文网首页SAS编程
198:因为一个error引发的对ODS的了解

198:因为一个error引发的对ODS的了解

作者: SASPRO的打工人生活 | 来源:发表于2023-02-26 23:12 被阅读0次

在读者群,看到好几次有读者问下面的问题如何解决,就是

ERROR: The width of col1 is not between 1 and 150. Adjust the column width or line size.

NOTE: This affects LISTING output.

col1可以是你数据集里面的任何变量

以前没在意,直到我自己也遇到了这个问题,当时还以为自己程序里面哪里写错了,但是单独跑程序的时候没有任何log,但是一batch,这个error又出现了。在SAS community找到了类似的问题以及相关人员的回答

If the error is a listing destination error and you are not using the listing destination, turn it off ( ods listing close;)

My memory says that in the listing destination a given column cannot be wider than the width of the paper (LINESIZE= system option).  So increasing the LINESIZE might change the error.

按照这位美女的说法(这个美女是proc report方面的专家,我搜report的东西一般都能看见她,零几年的回复就有她了,现在应该4-50十岁了),就是因为你没有提前关闭ods listing,导致在compute里面,如果你还有对变量进行计算的话,会重新计算宽度,这个就有可能超过你设置的linesize,所以会报那个错。

但是我也没有在compute里面进行任何计算,只是说要在哪个变量后面加上空行。但是我试了加上ods listing close,再batch run的时候,真的没有报这个错了,然后我发现出这个问题的程序都是忘记加上ods listing close。

以前写程序的时候,一般都会按照这个格式

ods listing close;

ods rtf file="XXX";

ods rtf close;

ods listing;

但是这次不知道怎么就忘了,看来犯错才是学习的第一步

于是又去搜索了一些关于ods listing的东西:

要了解ods listing,首先需要了解ODS(Output Delivery System),我摘抄一些官网上的内容:

The Output Delivery System (ODS) gives you great flexibility in generating, storing, and reproducing SAS procedures and DATA step output, with a wide range of formatting options.

With ODS, you can use ODS destination statements to create output in popular formats such as HTML, PDF, and RTF. For example, you can use the ODS PDF statement to create PDF files for viewing with Adobe Acrobat or for printing. You can use the ODS EPUB statement to create output for e-book readers. The ODS RTF statement creates output for Microsoft Word.

The PROC or DATA step supplies data and the name of the template that contains the formatting instructions. ODS formats the output. You can use ODS to format output from individual procedures and from the DATA step in many different forms.

ODS provides a way for you to choose individual output objects to send to ODS destinations. Most SAS procedures produce multiple output objects. You can easily create HTML output, an output data set, LISTING output, or printer output from any or all output objects. You can send different output objects to different destinations。

In the SAS windowing environment, ODS stores a link to each output object in the Results folder in the Results window.

The ODS HTML destination is turned on by default when you use the SAS windowing environment and SAS Studio.

上面这些东西来自SAS官网,ods html是相当于你打开SAS就自动打开的,但是ods listing\ods rtf这些没讲到,我觉得应该也是默认打开的。下面这些是我从相关文章里面找到的,我觉得可能会启发大家。

选择什么作为ods的输出,在SAS Base可以这样选择:Tools---Options---Preference

当我勾选create listing之后再跑这段程序的时候,

proc print data=sashelp.class;

run;

在左边的results结果出现了一个listing的结果,并显示在output窗口。看了一下资料,listing默认也是自动打开的。

我们在输出rtf文件的时候,为什么要先写ods listing close呢?我觉得一个是避免发生文章一开始的那个错误,另一个是避免资源浪费吧(我的猜想)

如果你想关闭所有的已经打开的destinations,可以通过ods _all_ close;我们在程序前面加上这句话,看下结果会怎么样?

左边没有显示任何东西,log也显示没有输出的目标

result窗口也没有重新输出。如果我们在ods _all_ close后面再加上ods listing;

可以看到重新输出了listing目标。

我觉得今天的文章只可意会,不可言传,后面应该还要再写一篇

相关文章

网友评论

    本文标题:198:因为一个error引发的对ODS的了解

    本文链接:https://www.haomeiwen.com/subject/ypbcldtx.html