![]() |
Don't Be a SAS® Dinosaur:
Modernize Your SAS Programs
Diagnostics: Write Messages to the SAS Log |
While writing text to an external file in a DATA step, you want to generate diagnostic messages to the SAS log when suspicious data is encountered.
The destination of text written by the PUT statement is determined by the previously executed FILE statement.
|
The original approach is to execute a FILE LOG statement prior to each diagnostic message, and then re-execute the FILE statement for the output file after the diagnostic message is complete. Download this program
data _null_;
file "c:\temp\Dinosaur\PutLogFile1.csv" dsd;
if _n_=1 then put "Name,Age,Height";
set sashelp.class;
if age lt 12 then do;
file log;
put "Student age is less than 12 ... Please verify for " name= age=;
file "c:\temp\Dinosaur\PutLogFile1.csv";
end;
put Name Age Height;
run;
SAS Log
1078 data _null_;
1079 file "c:\temp\Dinosaur\PutLogFile1.csv" dsd;
1080 if _n_=1 then put "Name,Age,Height";
1081 set sashelp.class;
1082 if age lt 12 then do;
1083 file log;
1084 put "Student age is less than 12 ... Please verify for " name= age=;
1085 file "c:\temp\Dinosaur\PutLogFile1.csv";
1086 end;
1087 put Name Age Height;
1088 run;
NOTE: The file "c:\temp\Dinosaur\PutLogFile1.csv" is:
Filename=c:\temp\Dinosaur\PutLogFile1.csv,
RECFM=V,LRECL=256,File Size (bytes)=0,
Last Modified=14May2008:20:21:17,
Create Time=05Aug2007:18:06:13
Student age is less than 12 ... Please verify for Name=Joyce Age=11
Student age is less than 12 ... Please verify for Name=Thomas Age=11
NOTE: 20 records were written to the file "c:\temp\Dinosaur\PutLogFile1.csv".
The minimum record length was 10.
The maximum record length was 15.
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
|
![]() |
|
An alternate approach is to use the PUTLOG statement for the diagostic messages. Download this program
data _null_;
file "c:\temp\Dinosaur\PutLogFile2.csv" dsd;
if _n_=1 then put "Name,Age,Height";
set sashelp.class;
if age lt 12 then
putlog "Student age is less than 12 ... Please verify for " name= age=;
put Name Age Height;
run;
SAS Log
1100 data _null_;
1101 file "c:\temp\Dinosaur\PutLogFile2.csv" dsd;
1102 if _n_=1 then put "Name,Age,Height";
1103 set sashelp.class;
1104 if age lt 12 then
1105 putlog "Student age is less than 12 ... Please verify for " name= age=;
1106 put Name Age Height;
1107 run;
NOTE: The file "c:\temp\Dinosaur\PutLogFile2.csv" is:
Filename=c:\temp\Dinosaur\PutLogFile2.csv,
RECFM=V,LRECL=256,File Size (bytes)=0,
Last Modified=14May2008:20:21:17,
Create Time=05Aug2007:18:07:45
Student age is less than 12 ... Please verify for Name=Joyce Age=11
Student age is less than 12 ... Please verify for Name=Thomas Age=11
NOTE: 20 records were written to the file "c:\temp\Dinosaur\PutLogFile2.csv".
The minimum record length was 10.
The maximum record length was 15.
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
Advantages
of the
alternate
approach:
|
|
Back to SAS Dinosaur home page Printable copy of this page (without sample output)
SAS and all other SAS Institute Inc. product or service names are registered trademarks
or trademarks of SAS Institute Inc. in the USA and other countries.
|