据我所知,在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有足够的探索。我在帮助文档中搜索,但一无所获。我的朋友告诉我这可能是一个预体验功能,你怎么知道的?请分享你的想法。
COMMENT
是一个与任何其他提交的语句一样的语句。本质上,它与*
相同,因为注释语句以第一个分号(;
(结尾。文档没有具体说明*
是COMMENT
的别名,但列出了* ... ;
和/* ... */
。
对包含注释块的多个语句进行注释的另一种方法是将代码嵌套在宏定义中。
示例:
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 ...
*/;
增强编辑器
- 评论
- 选择一个行块,然后按
Ctrl-/
所有行都将成为单独的/*original line*/
样式注释块
- 选择一个行块,然后按
- 取消注释
- 选择一个行块,然后按
Ctrl-Shift-/
每行的前导/*
和尾随*/
将被删除
- 选择一个行块,然后按
宏变量
使用值为或
*
的标志变量作为语句介绍,以启用或禁用语句。
%if %sysget(USERNAME)=Richard %then %do;
%let flag=*;
%end;
%else %do;
%let flag=;
%end;
&flag. PROC PRINT ...;
&flag. ...;
&flag. ...;
&flag. run;