2

如何在 DATA 步内的 PUT 语句中放置制表符?

我正在使用 SAS 输出处理日志:

if first.ref then
    PUT 'PROCESSING: ' ref ;

if InceptionDate > LossDate then 
    do; 
        if first.ref then
            PUT 'WARNING: ' ref ' inception date prior to the loss date!' / ref= / InceptionDate= / LossDate=; 
            ... do some stuff...
    end;

我希望PUT, 之后的换行符/缩进。如何插入制表符?

4

1 回答 1

3

以下是一些可能的方法:

data _null_;
    ref = 001;
    inceptiondate = '01jan1960'd;
    lossdate = '01jun1960'd;
    format inceptiondate lossdate yymmdd10.;

    /*Without indent*/
  PUT 'WARNING: ' ref ' inception date prior to the loss date!' / ref= / InceptionDate= / LossDate=;

    /*Move the pointer to the right by 1 before printing*/
  PUT 'WARNING: ' ref ' inception date prior to the loss date!' /  +1 ref= / +1 InceptionDate= / +1 LossDate=;

    /*Move the pointer to column 2 before printing*/
  PUT 'WARNING: ' ref ' inception date prior to the loss date!' /  @2 ref= / @2 InceptionDate= / @2 LossDate=;


    /*# of spaces seems to depend on where you put the tab characters in the line containing the put statement*/
  PUT 'WARNING: ' ref ' inception date prior to the loss date!' / ' ' ref= / '  ' InceptionDate= / '    ' LossDate=;

    /*Works in external text editor but not in the SAS log window*/
  PUT 'WARNING: ' ref ' inception date prior to the loss date!' / '09'x ref= / '09'x InceptionDate= / '09'x LossDate=;

run;

笔记

我不确定如何让该站点正确显示制表符 - 第三种方法涉及编写包含单引号中的制表符的代码。如果您复制并粘贴上面显示的代码,则会得到空格。在 SAS 中,制表符会在代码运行之前转换为空格,因此您在日志中的缩进量取决于您的制表符在代码中的位置,并且日志包含空格而不是制表符。

如果您使用 '09'x 方法,如果您将日志重定向到外部文件proc printto log = "c:\temp\my.log"; run;并在您最喜欢的文本编辑器中查看它,这将按预期工作,但 SAS 日志窗口(至少在 9.1.3 中)不支持制表符 - 它们被视为单个不可打印的字符,显示为矩形。

于 2014-09-03T07:32:37.643 回答