我将在SAS EG结束我的项目。该项目通过使用Prompt变量选择数据来创建一些Statement。有:
%let variable1 = name1
%let variable2 = name2
%let variable3 = name3
最终的proc打印代码是:
proc print data = mydata;
title "This statement created with &variable1 &variable2 &variable3"
但有一种情况是exaple variable3根本不存在于代码中。执行后我会得到:
"This statement created with name1 name2 &variable3"
有什么办法可以避免吗?谢谢。
答案 0 :(得分:1)
将proc打印放在宏中并检查变量是否存在:
%macro m;
proc print data = mydata;
title "This statement created with "
%if %Symexist(variable1) %then "&variable1 ";
%if %Symexist(variable2) %then "&variable2 ";
%if %Symexist(variable3) %then "&variable3";;
run;
%mend;
%m;
答案 1 :(得分:0)
将您的宏变量放在%Global或%Local语句中(取决于您的需要)。
%Global VARIABLE1 VARIABLE2 VARIABLE3;
%Let VARIABLE1=name1;
%Let VARIABLE2=name2;
/*%Let VARIABLE3=name3;*/
title "This statement created with &variable1 &variable2 &variable3";
Proc print data=sashelp.cars(obs=1); run;