在SAS中有条件地打印标题?

在SAS中有条件地打印标题?,sas,sas-macro,Sas,Sas Macro,我想为通过宏的不同变量显示不同的标题 %macro mplot(dsn,vn); title1 'hey!'; %if "&vn"="" %then title2 "Ooos" justify=left; %else title2 "Ooos &vn" justify=left; title3 "this line"; %mend mplot; %mplot(_avg); %mplot(_avgs1,s1); 理想的标题是: hey! Ooos this line hey!

我想为通过宏的不同变量显示不同的标题

%macro mplot(dsn,vn);
title1 'hey!';
%if "&vn"="" %then title2 "Ooos" justify=left;
%else title2 "Ooos &vn" justify=left;
title3 "this line";
%mend mplot;

%mplot(_avg);
%mplot(_avgs1,s1);
理想的标题是:

hey!
Ooos
this line

hey!
Ooos s1
this line
但结果是

hey!
Ooos
title3 this line

hey!
Ooos s1
title3 this line

我通过在它后面加一个分号来解决它

%macro mplot(dsn,vn);
title1 'hey!';
%if "&vn"="" %then title2 "Ooos" justify=left;
%else title2 "Ooos &vn" justify=left;;
title3 "this line";
%mend mplot;

但是我不明白为什么需要额外的分号。

也许您之前提交的一些代码缺少分号,这最终使您的SAS会话能够“赶上”分号。需要额外的分号来结束title语句。%IF语句以分号结尾。%else语句以分号结尾。当宏执行时,它将生成标题2 ooo,而不使用分号来结束title语句。额外的分号结束title语句。如果添加额外的%do;-%,分号会减少混淆终止梨:%i如果&vn=%n,则%do;标题2 Ooos justify=左;%结束;%否则%会;标题2 ooo&vn justify=左;%终止