SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3

PUTLOG Statement

Writes a message to the SAS log

Valid: in a DATA step

Category: Action

Type: Executable

Syntax

PUTLOG message ;

Arguments

message

Details

The PUTLOG statement writes a message that you specify to the SAS log.

The PUTLOG statement is helpful when you use macro-generated code because you can send output to the SAS log without affecting the current file destination.

Comparisons

The PUTLOG statement is similar to the ERROR statement except that PUTLOG does not set _ERROR_ to 1.

Examples

Example 1: Writing Messages to the SAS Log Using the PUTLOG Statement

The following program creates the computeAverage92 macro, which computes the average score, validates input data, and uses the PUTLOG statement to write error messages to the SAS log. The DATA step uses the PUTLOG statement to write a warning message to the log.

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 ; options pageno=1 nodate linesize=80 pagesize=60; filename outfile ' 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;

The following lines are written to the SAS log.

Output 7.24: SAS Log Results from the PUTLOG Statement

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

 

SAS creates the following output file.

Output 7.25: Individual Examination Scores

Exam Scores 1 Obs Name Score1 Score2 Score3 1 Sullivan, James 86 92 88 2 Martinez, Maria 95 91 92 3 Guzik, Eugene 99 98 . 4 Schultz, John 90 87 93 5 van Dyke, Sylvia 98 . 91 6 Tan, Carol 93 85 85

 

See Also

Statement:

Категории