前のページ|次のページ

PUTLOGステートメント

SASログにメッセージを書き込みます。

該当要素: DATAステップ
カテゴリ: アクション
種類: 実行

構文

PUTLOG 'message';

引数

message

SASログに書き込むメッセージを指定します。messageには、文字リテラル(一重引用符で囲む)、変数名、出力形式、ポインタコントロールを指定できます。

ヒント メッセージテキストの前に、WARNING、MESSAGE、NOTEなどを追加すると、ログの出力内容を判別しやすくなります。

詳細

PUTLOGステートメントでは、指定したメッセージをSASログに書き込みます。現在のファイル出力先に影響せずにSASログに出力するため、PUTLOGステートメントはマクロを生成するコードの使用時にも便利です。

比較

PUTLOGステートメントはERRORステートメントに似ていますが、PUTLOGステートメントを実行しても自動変数_ERROR_の値は1に設定されません。

例: PUTLOGステートメントを使用してメッセージをSASログに書き込む

次のプログラムでは、computeAverage92マクロを作成します。このマクロは、平均点の算出、入力データの検証、PUTLOGステートメントを使用したSASログへのエラーメッセージの書き込みを行います。DATAステップでは、PUTLOGステートメントを使用して警告メッセージをログに書き込みます。
data ExamScores;
   input Name $ 1-16 Score1 Score2 Score3;
   datalines;
Sullivan, James   86 92 88
Martinez, Maria   95 91 92
Guzik, Eugene     99 98 . 
Schultz, John     90 87 93
van Dyke, Sylvia  98 . 91
Tan, Carol        93 85 85 
;
 
filename outfile 'path-to-your-output-file';
   /* Create a macro that computes the average score, validates  */
   /* input data, and uses PUTLOG to write error messages to the */
   /* SAS log.                                                   */
%macro computeAverage92(s1, s2, s3, avg);
   if &s1 < 0 or &s2 < 0 or &s3 < 0 then
      do;
	        putlog 'ERROR: Invalid score data ' &s1= &s2= &s3=;
         &avg = .;
	     end;
	  else
	     &avg = mean(&s1, &s2, &s3);
%mend;
data _null_;
set ExamScores;
   file outfile;
   %computeAverage92(Score1, Score2, Score3, AverageScore);
   put name Score1 Score2 Score3 AverageScore;
      /* Use PUTLOG to write a warning message to the SAS log. */
   if AverageScore < 92 then
     	 putlog 'WARNING: Score below the minimum ' name= AverageScore= 5.2;
run;
  
proc print;
run;
次の行がSASログに書き出されます。
WARNING:Score below the minimum Name=Sullivan, James AverageScore=88.67 ERROR:Invalid score data Score1=99 Score2=98 Score3=.WARNING:Score below the minimum Name=Guzik, Eugene AverageScore=.WARNING:Score below the minimum Name=Schultz, John AverageScore=90.00 ERROR:Invalid score data Score1=98 Score2=.Score3=91 WARNING:Score below the minimum Name=van Dyke, Sylvia AverageScore=.WARNING:Score below the minimum Name=Tan, Carol AverageScore=87.67
次の出力ファイルが作成されます。
個人別のテスト結果
個人別のテスト結果

関連項目:

ステートメント:
前のページ|次のページ|ページの先頭へ