Statements |
Valid: | in a DATA step |
Category: | Action |
Type: | Executable |
Syntax | |
Arguments | |
Details | |
Comparisons | |
Examples | |
Example 1: Writing Messages to the SAS Log Using the PUTLOG Statement | |
See Also |
Syntax |
PUTLOG 'message'; |
Arguments |
specifies the message that you want to write to the SAS log. Message can include character literals (enclosed in quotation marks), variable names, formats, and pointer controls.
Tip: | You can precede your message text with WARNING, MESSAGE, or NOTE to better identify the output in the log. |
Details |
The PUTLOG statement writes a message that you specify to the SAS log. The PUTLOG statement is also 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 |
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.
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.
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 |
|
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.