The SAS Output Delivery System and reporting techniques

Print text in color in data _null_ step without using proc template?

Accepted Solution Solved
Reply
Super Contributor
Posts: 374
Accepted Solution

Print text in color in data _null_ step without using proc template?

* option 1 ;
data _null_;
   file print;
   msg="Testing 1,2,3";
   put msg;
run;

* option 2 ;
data _null_;
   file print ods;
   msg="Testing 1,2,3";
   put msg _ods_;
run;

 

SAS 9.3

 

I've skimmed http://www2.sas.com/proceedings/sugi30/088-30.pdf.

 

All I want to do is print the text red bold so it stands out, and also suppress the variable name.  It's an error message in a stored process called from EG.

 

I suppose I could use proc template; I was hoping I didn't have to for such a simple task.

 

I just want option 2 to mimic option 1, but in red bold.  I suppose centered within the current linesize would be cool too.

 

 

 

 

 


Accepted Solutions
Solution
‎11-30-2016 04:33 PM
SAS Super FREQ
Posts: 8,715

Re: Print text in color in data _null_ step without using proc template?

Hi:

  And to modify RW9's suggestion, you can add a blank label statement to get rid of the header, but not of the area reserved for the header.

 

  But PROC REPORT could do it for you without a header and without a template.

 

cynthia

 


ods html(id=msg1) file='c:\temp\message1.html';
ods escapechar='^';
data _null_;
   file print ods;
   msg="^{style[color=red font_weight=bold font_size=20pt]Testing 1,2,3}";
   put @1 msg ;
   label msg = ' ';
run;
ods html(id=msg1) close;
    
ods html(id=msg2) file='c:\temp\message2.html';
ods escapechar='^';
data msg;
   msg="Testing 1,2,3";
run;
  
proc report data=msg noheader;
  column msg;
  define msg / display style(column)={color=red font_weight=bold font_size=20pt};
run;
ods html(id=msg2) close;

View solution in original post


All Replies
Esteemed Advisor
Esteemed Advisor
Posts: 7,185

Re: Print text in color in data _null_ step without using proc template?

Have you tried inline formatting:

ods escapechar='^';

data _null_;
   file print;
   put '^S={foreground=red}Testing 1,2,3';
run;
Solution
‎11-30-2016 04:33 PM
SAS Super FREQ
Posts: 8,715

Re: Print text in color in data _null_ step without using proc template?

Hi:

  And to modify RW9's suggestion, you can add a blank label statement to get rid of the header, but not of the area reserved for the header.

 

  But PROC REPORT could do it for you without a header and without a template.

 

cynthia

 


ods html(id=msg1) file='c:\temp\message1.html';
ods escapechar='^';
data _null_;
   file print ods;
   msg="^{style[color=red font_weight=bold font_size=20pt]Testing 1,2,3}";
   put @1 msg ;
   label msg = ' ';
run;
ods html(id=msg1) close;
    
ods html(id=msg2) file='c:\temp\message2.html';
ods escapechar='^';
data msg;
   msg="Testing 1,2,3";
run;
  
proc report data=msg noheader;
  column msg;
  define msg / display style(column)={color=red font_weight=bold font_size=20pt};
run;
ods html(id=msg2) close;
Super Contributor
Posts: 374

Re: Print text in color in data _null_ step without using proc template?

[ Edited ]

There's a bug in the forum software when you click on Preview and have embedded SAS code, then edit that post. 

 

The gist is I lost the surrounding commentary of this post, and it's not worth recreating in lieu of my follow on post.

 

Since I can't delete this post, here is the remnants of that post, superceded by the below post:

 

ods escapechar='^';

data _null_;
   file print ods;
   msg="^{style[color=red font_weight=bold font_size=12pt]Testing 1,2,3}";
   put @1 msg ;
   label msg = ' ';
run;
 
data msg;
   msg1="Testing 1,2,3";
   msg2="^{style[color=red font_weight=bold font_size=12pt]Testing 1,2,3}";
run;

proc print data=msg noobs label;
   var msg2;
   label msg2='00'x; * a simple space does not work ;
run;
 
proc report data=msg noheader;
   column msg1;
   define msg1 / display style(column)={color=red font_weight=bold font_size=12pt};
run;

proc report data=msg noheader;
   column msg2;
   define msg2 / display;
run;

proc delete data=msg;
run;

 

Super Contributor
Posts: 374

Re: Print text in color in data _null_ step without using proc template?

[ Edited ]

Further Googling led me to this usage note:  http://support.sas.com/kb/23/353.html

 

I assume there is no way to create "enhanced output" via data _null_ / file print ods without using proc template.  For my purposes, that's more effort than I want to expend to just color code an error message.

 

Embedding style data within the data itself does not seem to work.

 

Here is some additional code, with both proc print and proc report creating enhanced output:

 

ods escapechar='^';

data _null_;
   file print;
   msg="Testing 1,2,3";
   put msg;
run;

data _null_;
   file print ods;
   msg="^{style[color=red font_weight=bold font_size=12pt]Testing 1,2,3}";
   put @1 msg;
   label msg = '00'x;
run;
     
data msg;
   msg1="Testing 1,2,3";
   msg2="^{style[color=red font_weight=bold font_size=12pt]Testing 1,2,3}";
run;

proc print data=msg noobs label;
   var msg1 / style={color=red font_weight=bold font_size=12pt};
   label msg1='00'x; * a simple space does not work ;
run;
 
proc print data=msg noobs label;
   var msg2;
   label msg2='00'x; * a simple space does not work ;
run;
 
proc print data=msg noobs label;
   var msg2 / style={color=red font_weight=bold font_size=12pt};
   label msg2='00'x; * a simple space does not work ;
run;
 
proc report data=msg noheader;
  column msg1;
  define msg1 / display style(column)={color=red font_weight=bold font_size=12pt};
run;

proc report data=msg noheader;
  column msg2;
  define msg2 / display;
run;

proc delete data=msg;
run;
Attachment
Esteemed Advisor
Esteemed Advisor
Posts: 7,185

Re: Print text in color in data _null_ step without using proc template?

Hi,

 

Sorry, it wasn't clear to me what "wasn't working", the color seems to work on all those statements for me other than the first.  

 

Also, I think you may have a misonception here.  The log file is the place for errors/warnings and such like, color coding is defined there by the use of those keywords.  Output window is for output, i.e. report/print and procedure output.  Normally this is plain text, however you can set it to HTMLwhich then has the formatting.  However that being said, if your producing output then you would find it far simpler and more robust to produce a report, than putting out bits of text there.  Its not difficult to have an errors dataset, which you insert each problem you come across into, and then at the end proc report this to a file.

 

Super Contributor
Posts: 374

Re: Print text in color in data _null_ step without using proc template?

[ Edited ]

I've edited my previous post, attaching a screenshot of the results in my EG6.1M1 / SAS 9.3 environment.

 

Thanks for the advice regarding coding approaches.  For my particular application I am happy with my current approach - using the output window to give feedback to the end user, including error messages.

 

If we had SAS/AF licensed (and I had a mandate to use it), I would use it rather than EG for this particular programming task.  I could use a custom task for this but that too is not mandated by my mangement or end users.

 

Esteemed Advisor
Esteemed Advisor
Posts: 7,185

Re: Print text in color in data _null_ step without using proc template?

Must be your setup/process then.  In 9.4 normal SAS it works fine.  Am afraid I don't have EG to check that.  I would really not recommend using AF, I can't think of anything more clunky/outdated than that.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 377 views
  • 1 like
  • 3 in conversation