Valid in: | DATA step |
Category: | Action |
Type: | Executable |
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;
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