/************************************************************* * * Summarize SAS-log: Exctract errors and warnings * * Syntax: * %SummarizeLog(logfile=,out=log) * * Parameters: * logfile filename to store log in, default is WORK(temp.log) * out output file (default=log, alternatives are print or "filename") * * Saves SAS-log in a file, reads it back in extracting error messages and warnings. * *************************************************************/ %MACRO SummarizeLog(logfile=,out=log); %LOCAL wordpath logfile optstore; %LET optstore=%sysfunc(getoption(notes)); option nonotes; %IF %bquote(&logfile.)=%str() %THEN %DO; %LET workpath=%sysfunc(pathname(work)); %LET logfile=&workpath\temp.log; %END; dm log 'file "&logfile." replace'; data _null_; file &out.; if _N_=1 then put '----- LOG SUMMARY:'; infile "&logfile." end=eof; length txt $100 pre type subtype $10; retain type subtype '' include 1; input pre:$1-6; txt=_infile_; if trim(txt)= '----- LOG SUMMARY:' then include=0; else if trim(txt)='----- LOG ENDED.' then include=1; if include then do; if substr(txt,1,1)^=' ' then do; type=scan(txt,1,' '); if compress(type,'0123456789')='' then type='#'; else if type in ('NOTE:','ERROR:','WARNING:') then; else type=''; if type='NOTE' then do; subtype=''; end; else subtype=''; end; if type in ('ERROR:','WARNING:') then put txt; end; if eof then put '----- LOG ENDED.'; run; option &optstore.; %MEND;