gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 09:31:17 24 4
gpt4 key购买 nike

据我所知,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中有足够的探索。我在帮助文档中搜索,什么也没找到。我的 friend 告诉我这可能是一个预体验功能,你是怎么知道的?请分享你的想法。

最佳答案

COMMENT是与任何其他提交的声明一​​样的声明。本质上与 * 相同。因为注释语句以第一个分号 ( ; ) 结束。文档没有具体说明 *COMMENT 的别名, 但列出 * ... ;/* ... */ .
注释多个还包含注释 block 的语句的另一种方法是将代码嵌套在宏定义中。
例子:

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;
...
其他评论技巧
方式一 - /**/
如果代码始终只使用 *; 进行注释样式注释,然后可以使用介绍性 /**/ 轻松注释和取消注释代码块或 /** /和结束 /**/ .
未注释 - 介绍是简单的注释
/**/  * some code here; /**/
已评论 - 介绍中的额外空格导致评论被最终 */ 关闭
/** / * some code here; /**/
方式二 - /* *; */;切换
需要 *;注释作为 block 的第一行,没有 /* */内的评论。
关闭, block 代码被注释掉
/*
*intro;
... block ...
*/;
相对
开启, block 代码不被注释掉
*/*
*intro;
... block ...
*/;
增强编辑器
  • 评论
  • 选择一行行并按Ctrl-/ .所有的行都会变成单独的/*original line*/样式注释 block 。

  • 取消注释
  • 选择一行行并按Ctrl-Shift-/ .领先/*和尾随 */将删除每一行。


  • 宏变量
    使用值为 的标志变量或 *作为启用或禁用 的介绍性声明声明 .
    %if %sysget(USERNAME)=Richard %then %do;
    %let flag=*;
    %end;
    %else %do;
    %let flag=;
    %end;

    &flag. PROC PRINT ...;
    &flag. ...;
    &flag. ...;
    &flag. run;

    关于sas - 这是在SAS中添加注释文本的第四种方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62832294/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com