SAS中此%宏函数的输出将是什么以及如何在SAS Studio中显示输出
%macro segm1;
data _null_;
%do i=0 %to 8;
call symput("yyyymm_i",put(intnx('month',today(),-1,'b'),yymmn6.));
%end;
%mend;
%segm1;
run;
SAS工作室中此宏代码的输出以及如何获取/dispaly/tive输出将是什么?
%macro segm1;
data _null_;
%do i=0 %to 8;
call symput("yyyymm_i",put(intnx('month',today(),-1,'b'),yymmn6.));
%end;
%mend;
%segm1;
run;
What will be the output and how to get/dispaly/view output of this macro code in sas studio?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于宏用于生成SAS代码,以在运行之前查看MAPRINT选项的输出。您将看到宏生成数据语句和8个调用Symput语句。
该代码有很多问题。
如果要创建8个宏变量,只需使用普通的DO循环即可。无需宏。使用循环变量的值更改生成的宏变量的名称以及结果表示的月份。
它将创建一系列名为yyyymm_0到yyyymm_8的宏变量,并用六位数字字符串(如202204,202203),...代表当前月至八个月前,
如果您想在宏中运行该宏并具有宏变量,则它会创建它。在宏结束后可用,然后将可选的第三个参数设置为将Symputx()调用到字符串“ G”,以便将它们定义在全局符号表中而不是本地符号表中。
Since a macro is used to generate SAS code to view the output of macro set the MPRINT option before running it. You will see that the macro generates a data statement and 8 call symput statements.
There are a lot of problems with that code.
If you want to create 8 macro variables just use a normal DO loop. No need for a macro. Use the value of the loop variable to change the name of the macro variable generated and the month the result represents.
Which will create a series of macro variables named YYYYMM_0 to YYYYMM_8 with six digit strings like 202204 , 202203 , ... representing the current month back to eight months ago
If you did want to run that inside a macro and have the macro variables it creates available after the macro ends then set the optional third parameter to call symputx() to the string 'G' so that they are defined in the global symbol table instead of the local symbol table.
您可以使用
%put
语句将单个宏变量打印到日志中,例如%put& yyyymm_i;
您可以使用
>%put _all_;;
,或者,如果您仅对自己创建的变量感兴趣:%put _user _;
(或在宏%内部put put put _local _;
)代码是错误的,请尝试
You can print individual macro variables to the log with the
%put
statement, like%put &yyyymm_i;
You can print all macro variable with
%put _all_;
, or if you are only interested in variables you created yourself:%put _user_;
(or within a macro%put _local_;
)By the way, your code is wrong, try this