Send As SMS

Wednesday, January 24, 2007

Using a dynamic style directive in PROC REPORT

This example was written in response in a question on SAS-L. Someone wanted to know how to force a line split within an cell. As it happens, the mechanism to do that is the same mechanism used to make part of the output bold or in a different font - ODS.

This should work for RTF and PDF output in SAS 8.2 and later (maybe earlier, but I can't check), and for HTML in 9.1.3 (but HTML in 8.2 doesn't work right).

data x;                                                                                                                                 
  text1='hello';                                                                                                                        
  text2='everyone';                                                                                                                     
  output;                                                                                                                               
run;                                                                                                                                    
                                                                                                                                        
ods listing close;                                                                                                                      
ods rtf file='h:\temp\test.rtf';                                                                                                        
ods pdf file='h:\temp\test.pdf';                                                                                                        
ods escapechar='^';                                                                                                                     
                                                                                                                                        
proc report data=x nowindows missing;                                                                                                   
  column text1 text2 text;                                                                                                              
  define text1-text2 / noprint;                                                                                                         
  define  text / computed;                                                                                                              
  compute text / character length=200;                                                                                                  
     text = '^S={font_face=courier font_weight=bold}' || text1
            || ' ^n^S={font_face=times font_style=italic}' || text2;                 
  endcomp;                                                                                                                              
run;                                                                                                                                    
                                                                                                                                        
ods rtf close;                                                                                                                          
ods pdf close;                                                                                                                          
ods listing;                                                                                                                            

The key here is the use of style directives. ^S tells SAS that style information will follow, and ^n means "insert a line break".

0 Comments:

Post a Comment

<< Home