有没有办法在 SAS 注释周围创建一个星号框?

Is there a way to create a box of asterisks around a SAS comment?

我想知道是否有一种方法可以在 SAS 中围绕评论快速创建一个框。目前,您可以使用命令 Ctrl + Shift + / 创建评论,例如

/*This is a comment*/
/*This is the second line of the comment*/

我想知道有没有人有解决多行评论的方法,像这样:

/******************************************/
/* This is a comment                      */
/* This is the second line of the comment */
/******************************************/

目前我知道如何创建这样的框的唯一方法是手动输入星号并添加空格,直到代码对齐。我希望有一个更有效的解决方案。

假设您使用的是企业指南,您是否尝试过使用键盘宏部分?

例子

这是一个非常快速的方法,它只是插入一个设定长度的 /*****/,但其中可能有足够的功能来根据您的评论长度正确设置它的长度。

然后您可以将其分配给组合键。

此宏将在日志中创建评论框。然后您可以将其复制并粘贴到您的代码中。

它使用'/'作为默认分隔符来分割行。但是这个可以在调用宏的时候改变,如下图

%macro comment_box(comment, delimiter='/');
    /* count the number of line using the delimiter */ 
    %let line_count = %sysevalf(%sysfunc(countc(%str(&comment.), &delimiter.)) + 1);
    %let max_line_len = 0;
    /* loop through to split the text into lines measure the line length including leading&trailing blanks */
    %do x=1 %to &line_count.;
        %let line&x. = %scan(%str(&comment.), &x., &delimiter.);
        %let line&x._len = %sysevalf(%length(%str(&&line&x..)) + 2);
        %if &&line&x._len. > &max_line_len. %then %let max_line_len = &&line&x._len.;
    %end;

    /* Create the top/bottom box line matching to the max text line length */
    /* Add the comment box to the log using PUT statements. */
    option nonotes;
    data _null_;
        line_count = &line_count.;
        max_line_len = &max_line_len.;
        box_line = cat('/*', repeat('*', max_line_len - 1), '*/');
        %do x=1 %to &line_count.;
            %if &max_line_len. = &&line&x._len. %then %do;
                line&x. = cat('/* ', "&&line&x..", ' */');
            %end;
            %else %do;
                line&x. = cat('/* ', "&&line&x..", repeat(' ', %sysevalf(&max_line_len. - &&line&x._len. - 1)), ' */');
            %end;
        %end;
        /* add the comment box to the log */
        put box_line;
        %do x=1 %to &line_count.;
            put line&x.;
        %end;
        put box_line;
    run;
    option notes;
%mEnd;


%comment_box(%str(This is a comment/This is the second line of the comment));
%comment_box(%str(This is a comment+This is the second line of the comment), delimiter= '+');