2016-06-15 7 views
1

私はSAS EGでプロジェクトを終了します。このプロジェクトは、プロンプト変数を使用してデータを選択することによって、いくつかのStatementを作成します。最終のproc印刷コードがあるproc print sasのタイトルEG

%let variable1 = name1 
%let variable2 = name2 
%let variable3 = name3 

:あり

proc print data = mydata; 
title "This statement created with &variable1 &variable2 &variable3" 

しかしexaple variable3はのためのすべてのコードに存在しない状況があります。実行後より私は得る:

"This statement created with name1 name2 &variable3" 

それを避ける方法はありますか?ありがとうございました。

答えて

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; 
+0

ありがとうございます! – bobby1232

0

は、(必要に応じて)%グローバルまたはローカル%声明の中で、あなたのマクロ変数を入れてください。

%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;