Sample 24739: Send output to log while creating an external file
Write information as needed to the SAS log while writing an
external file.
/* SAS 9 introduces the PUTLOG statement to write messages to the SAS log */
/* while writing to a flat file. In Example 1 below, only NAME would be */
/* written to the external file, while the message "Encountered first male" */
/* would be written to the SAS log. */
/* */
/* If you are running prior to SAS 9, you can get the same result using */
/* macro logic. See the alternative technique illustrated in Example 2 below. */
/* Example 1 - PUTLOG */
proc sort data=sashelp.class out=class;
by name;
run;
data _null_;
set class (obs=5);
file print;
put name;
if name= 'Alfred' then putlog "Encountered first male on observation " _n_;
run;
/* Example 2 - Prior to SAS 9.0 */
/* Using a macro to write to log rather than flat file. */
/* Type the macro 'as is'. Edit the text to be written to the log where */
/* you call the macro in your DATA step. */
%macro putlog(msg);
drop __RC;
__RC = _ERROR_;
error &msg;
_ERROR_ = __RC;
%mend;
data one;
file print;
input a;
if a=4 then do;
%putlog("Value is 4");
end;
else put 'and the answer is ' a= ;
datalines;
1
2
3
4
5
;
Example1 -- OUTPUT written to FILE PRINT
Alfred
Alice
Barbara
Carol
Henry
OUTPUT written to LOG
Encountered first male on observation 1
Example 2 -- OUTPUT written to FILE PRINT
and the answer is a=1
and the answer is a=2
and the answer is a=3
and the answer is a=5
OUTPUT written to LOG
Value is 4
Write information as needed to the SAS log while writing an
external file.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step Common Programming Tasks ==> Reading and Writing External Data
|
| Date Modified: | 2005-12-08 11:34:28 |
| Date Created: | 2004-09-30 14:09:09 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |