这是在SAS中添加注释文本的第四种方法吗?

这是在SAS中添加注释文本的第四种方法吗?,sas,Sas,据我所知,在SAS中添加注释有三种方式: *Any comment text here; %*Any comment text here; /*Any comment text here*/ 今天下午,我有点激动地发现了第四种添加评论的方式,这是巧合。它是: comment Any comment text here; 如您所见,这里的第一个单词comment是一个关键字,用于触发以下文本成为注释文本。我尝试了几个程序: /*comment of macro in open code*/ %

据我所知,在SAS中添加注释有三种方式:

*Any comment text here;
%*Any comment text here;
/*Any comment text here*/
今天下午,我有点激动地发现了第四种添加评论的方式,这是巧合。它是:

comment Any comment text here;
如您所见,这里的第一个单词
comment
是一个关键字,用于触发以下文本成为注释文本。我尝试了几个程序:

/*comment of macro in open code*/
%put This is %sysfunc(date(),e8601da.);
comment %put This is %sysfunc(date(),e8601da.);

/*comment of macro*/
comment %cmprs(test);

/*comment after normal statement*/
data _null_; comment Hi there.;
run;
它们的行为都像正常的注释方式。只有一点,注释文本中不能有分号


我认为在SAS中有足够的探索。我在帮助文档中搜索,没有找到任何内容。我的朋友告诉我这可能是一个预先体验的功能,你怎么知道的?请分享您的想法。

评论
与其他提交的声明一样是一种声明。本质上,它与
*
相同,因为注释语句以第一个分号(
)结尾。本文档未明确说明
*
注释的别名,但列出了
*
/**/

注释也包含注释块的多个语句的另一种方法是将代码嵌套在宏定义中

例如:

proc print data=sashelp.class;
run;

%macro MY_COMMENT;

* This part contains more statements;
proc print sashelp.cars;
run;
/* And there are comments in both styles of commenting */
%* But inside an uncalled macro everything acts like a giant comment block;

%mend MY_COMMENT;

* return to normal processing;
对于非常大的注释代码块,在代码开发过程中,我经常使用
NOSOURCE
SOURCE
来包装注释部分,以防止日志阻塞

...

options NOSOURCE;
/*
Big chunk commented out during development to temporarily prevent
rerunning ETL process steps or regenerating already OK reporting code
*/
options SOURCE;

* work on new additional part of process flow here;
...
其他评论技巧

方式1-
/**/

如果代码始终只注释
*样式注释,然后可以使用介绍性的
/***/
/***/
和结束语
/***/
轻松注释和取消注释代码块

未注释-介绍是一个简单的注释

/**/  * some code here; /**/
注释-介绍中的额外空格导致注释被最后的
*/

/** / * some code here; /**/
方式2-
/**切换

需要一个
*注释作为块的第一行,并且块中没有
/**/
注释

关闭时,将注释掉块代码

/*
*intro;
... block ...
*/;
*/*
*intro;
... block ...
*/;

打开时,块代码不会被注释掉

/*
*intro;
... block ...
*/;
*/*
*intro;
... block ...
*/;
增强型编辑器

  • 评论
    • 选择一个行块,然后按Ctrl-/

所有行都将成为单独的
/*原始行*/
样式注释块
  • 取消注释
    • 选择一组行,然后按Ctrl-Shift-/

  • 将删除每行的前导
    /*
    和尾随
    */
    宏变量

    使用值为
    *
    的标志变量作为启用或禁用语句的说明

    %if %sysget(USERNAME)=Richard %then %do;
      %let flag=*;
    %end;
    %else %do;
      %let flag=;
    %end;
    
    &flag. PROC PRINT ...;
    &flag. ...;
    &flag. ...;
    &flag. run;
    

    你也可以把你的评论拼错为“这是我的评论”
    @AllanBowe,哈哈,你说得对。为什么使用宏注释,不能做同样的事情呢?在SAS块注释中,注释不嵌套,所以
    /*…1…/*。。。2... */ ...3... */
    不会注释掉
    …3…
    我不得不再说一遍,你太有知识了。如果你是老师,我就是你的学生。