DATA Step, Macro, Functions and more

SAS Log in HTML format

Posts: 72

SAS Log in HTML format

I want to output the SAS log to a html file. When it gets printed in html file I want to see the log same as in SAS log window with different color settings for different warnings and errors. Please let me know is this possible. If yes please let me know.
Valued Guide
Posts: 632

Re: SAS Log in HTML format

I am hoping that someone will come up with a better answer.

It is easy to write the LOG to a text file (PROC PRINTTO or ALTLOG=), but any formatting will be lost. To my knowledge there is no way to capture this text in a file other than as text. I wish that there was an ODS destination that would capture the LOG as some procedures write information to the log that I would like to harvest.
Valued Guide
Posts: 2,175

Re: SAS Log in HTML format

I understand that just parsing the text of the LOG won't catch all NOTE lines, because of the nice feature introduced (iirc) in SAS9.
PUT 'NOTE- message with NOTE formatting but no NOTE: prefix' ;

of course ...
As it is the old display manager which established the log coloring expectations, it is not surprising that it offers a potential solution.
A command which could be executed as a statement, like

dm "file log 'some path/file with-attrs.log' attrs replace " ;

Stores the log lines in a special kind of way...
Having attrs stored with the text of the log, should maybe, allow some conversion to be derived.

However, opening 'some path/file with-attrs.log' with windows notepad, I don't recognise the attrib structure, but am reassured that the content is present because submitting the SAS code
proc fslist file= 'some path/file with-attrs.log' ; run;
displays the log content without attributes.

Respected Advisor
Posts: 3,777

Re: SAS Log in HTML format

I found the ATTR option most interesting as I was completly unaware of it. I'm unaware of most SAS things.

I used the program below, and found what seems to account for the line colors which may be in error or incomplete. When the ATTR option is used each log record is appended with a '00'x followed by either '20'x, 'F0'x, '10'x, '40'x. These hex characters are to equal the LS. I suppose that each character could have a different color. Run the program to see.

'20'x red
'F0'x black
'10'x blue
'40'x green

dm 'clear log;';
options ls=64;
data test;
x=1 *;
dm "log; file with-attrs.log attr replace";
options ls=256 center=0;
data _null_;
infile 'with-attrs.log' lrecl=1024;
options ls=64;

I'm off to experiment with the program editor. Message was edited by: data _null_;
Valued Guide
Posts: 2,175

Re: SAS Log in HTML format

data _null_;
rather than experiment with that old pgm-editor, try the notepad editor. There you can choose the color without restriction (just the limited list of colors).
- mark/select text and use command-line command
color mtext {color name}

Two (more modern) coloring systems exist. Each can be persuaded to deliver rtf-format information including color tags to the clipboard. I guess it would be possible to create a coloring scheme for .LOG files, but I have not had a go, yet.
As well as text (F0), note (10), warning(40) and error(20) line color attrs there is also DATA. This which got attr
'C0'x when I requested magenta
'60'x for yellow
'61'x for yellow highlight
'62'x is yellow underlined
'68'x is yellow reverse-video
'64'x is yellow blinking
guess '6F'x
........ no prizes
Fortunately, my system doesn't render the blinking as flashing attrib, but you could, and probably should, get rtf to carry all these attributes, if you really want to make your log file exactly as it is supposed to display in the SAS Log window of display manager .....

Does SAS Enterprise Guide render color like this for the Log viewer?

Where does the original poster want to draw the line with all this coloring potential?

The old SAS System Viewer renders log files with the words note, warning and error in the familiar coloring (blue, green, red) but that is controlled by options. and only that work is colored, not the whole line.

Does the newer SAS Universal Viewer achieve better support for rendering SAS Logs?

Posts: 8,743

Re: SAS Log in HTML format

Techniques simliar to what's shown for reading in a .SAS program in this posting would work for the SAS log.䆼

I used to have a program that would highlight the first line of NOTE, ERROR or WARNING in a saved log. I'll have to dig it out of my backup.

Posts: 8,743

Re: SAS Log in HTML format

I dredged the program out of the depths. Turns out that it uses the older style of ODS ESCAPECHAR to do color coding. So the program should still work in 9.1.3 and 9.2.

options ls=132 ps=60 orientation=landscape nocenter;
goptions reset=all;

** create an ASCII text file from the log;
** start capture of log output;
title; footnote;
ods listing;
proc printto log='c:\temp\mylogfile.txt' new;

proc print noobs;
title 'My Proc Print';

proc freq;
title 'My PROC FREQ';
tables product;

proc options group=errorhandling;

dtaa new;
set sashelp.class;

data new
set sashelp.class;

proc printto; run;
** end capture of log output;

** Create macro variables for red (error), green (warning) and blue (note) styles ;
%let wstyl = %str(~S={foreground=green font_weight=bold});
%let estyl = %str(~S={foreground=red font_weight=bold});
%let nstyl = %str(~S={foreground=blue font_weight=bold});

** Read log file into a SAS dataset;
data logcopy;
retain hiflag;
length line $132 newline $200;
format line $char132. newline $char200.;
infile 'c:\temp\mylogfile.txt' length=lgvar;
input @1 line $varying. lgvar;

gotwarn = indexw(line,'WARNING');
goterr = indexw(line,'ERROR');
gotnote = indexw(line,'NOTE:');


** test for log numbers or empty line in log or first log line;
** and set hiflag to 'none';
if _n_ = 1 or lgvar = 0 or anydigit(substr(line,1,1)) gt 0 then do;
hiflag = 'none';

** Set hiflag for how to highlight this line and subsequent lines;
** using ODS ESCAPECHAR S= function.;
** This should be first line of ERROR, NOTE: or WARNING;
if gotwarn gt 0 or goterr gt 0 or gotnote gt 0 then do;
if gotwarn gt 0 then do; hiflag = 'warn'; end;
if goterr gt 0 then do; hiflag = 'err '; end;
if gotnote gt 0 then do; hiflag = 'note'; end;

** Do not change color of line if hiflag = none;
if hiflag = 'none' then do; newline = line; end;
else if hiflag = 'warn' then do; newline = "&wstyl"||line; end;
else if hiflag = 'err ' then do; newline = "&estyl"||line; end;
else if hiflag = 'note' then do; newline = "&nstyl"||line; end;
** Set or keep highlighting if this or previous line was ERROR, NOTE: or WARNING;

label linenum = 'Num'
newline='SAS Log Line';

ods listing close;
options nodate nonumber orientation=landscape;
ods pdf file='c:\temp\rep_newlog.pdf';
ods rtf file='c:\temp\rep_newlog.rtf';
ods html file='c:\temp\rep_newlog.html' style=sasweb;

ods escapechar='~';

proc report data=logcopy nowd noheader
style(report)={rules=none frame=void asis=on cellspacing=0
font_face="SAS Monospace"
style(column)={font_face="SAS Monospace"
column linenum NewLine;
define linenum / order noprint;
define NewLine /display f=$char200.;
title 'Print of Log with PROC REPORT and NOHEADER';

ods _all_ close;

** note asis=on preserves indenting in the LOG, but causes HTML to look;
** as though it is double spaced.;
ods listing; title; footnote;
Super User
Posts: 9,681

Re: SAS Log in HTML format

Hi. I only know how to make log looks like exactly in SAS log window in a picture.But the color of text in this picture is all black. so you can use photoshop to make a chang or use proc gprint and annotate dataset to achieve what you need.But I am not familiar with annotate dataset,you can see its documentation by yourself.And if you can ,hope to put this picture into your html file.
the code isSmiley Sadthe name of picture is 'logGraph')

filename logtxt 'c:\temp\log.txt';
goptions reset=all;
proc printto log=logtxt;
proc print data=sashelp.class;
proc printto;
proc gprint fileref=logtxt name='logGraph';

Ksharp Message was edited by: Ksharp
Ask a Question
Discussion stats
  • 7 replies
  • 6 in conversation