Help using Base SAS procedures

PROC FORMAT, font weight and ODS

Accepted Solution Solved
Reply
Contributor
Posts: 54
Accepted Solution

PROC FORMAT, font weight and ODS

I would like to apply a bold font weight to some text I have in a PROC FORMAT.  This what I have:

 

ods escapechar='^';

 
proc format;
  value SC
     0      ='^{style [foreground=red   font_size=9pt] ^{unicode 25B6}}'
     0<-high='^{style [foreground=blue  font_size=9pt] ^{unicode 25B2}}'
     low-<0 ='^{style [foreground=green font_size=9pt] ^{unicode 25BC}}';
run;
 
proc format;
   value FD
      'TEXT 1' = 'white'
   'TEXT 2' = '^{style [foreground=white fontweight=bold]}';
run;
 
The foreground for 'TEXT 1' renders as white, as intended, but the foreground for 'TEXT 2' is rendered in black.  Is it because it cannot render the color white as bold? 

Accepted Solutions
Solution
‎02-02-2018 01:31 PM
Super User
Posts: 13,523

Re: PROC FORMAT, font weight and ODS

Posted in reply to JohnSAScom

The way you are attempting to use your FD format won't work because FOREGROUND will not recognize anything other than a color as a valid value.

You would need two formats, one for color and the other for font weight.

proc format;.
   value $FD
   'TEXT 1' = 'white'.
   'TEXT 2' = 'white'
   ;
   value $FW
   'TEXT 1' = 'normal'.
   'TEXT 2' = 'bold'
   ;
run;.
 .
proc tabulate data=DAT s=[font=("arial")];.
  class UA;.
  classlev UA / style={foreground=$FD. fontweight=$FW. font=("arial")};.
  var X / style={font=("arial") fontweight=bold};.
  table UA, X;.
run;.

You don't show how  you are using SC but I suspect that you actually want 3 formats, foreground, fontsize for style overrides and the Unicode value to be displayed

 

View solution in original post


All Replies
Super User
Posts: 13,523

Re: PROC FORMAT, font weight and ODS

Posted in reply to JohnSAScom

Show how you are generating output, proc print, report, tabulate or other procedure. There are minor differences between them depending on where the style elements are to be applied.

 

And some examples of the data as data step would help.

Information of which ODS style you are using may be helpful as well.

Contributor
Posts: 54

Re: PROC FORMAT, font weight and ODS

ods escapechar='^';
 
proc format;
        value SC
                       0      ='^{style [foreground=red font_size=9pt] ^{unicode 25B6}}'
                0<-high='^{style [foreground=blue font_size=9pt] ^{unicode 25B2}}'
                low-<0 ='^{style [foreground=green font_size=9pt] ^{unicode 25BC}}';
run;
 
proc format;
        value $FD
        'TEXT 1' = 'white'
        'TEXT 2' = '^{style [foreground=white fontweight=bold]}';
run;
 
proc tabulate data=DAT s=[font=("arial")];
  class UA;
  classlev UA / style={foreground=$FD. font=("arial")};
  var X / style={font=("arial") fontweight=bold};
  table UA, X;
run;
 
Solution
‎02-02-2018 01:31 PM
Super User
Posts: 13,523

Re: PROC FORMAT, font weight and ODS

Posted in reply to JohnSAScom

The way you are attempting to use your FD format won't work because FOREGROUND will not recognize anything other than a color as a valid value.

You would need two formats, one for color and the other for font weight.

proc format;.
   value $FD
   'TEXT 1' = 'white'.
   'TEXT 2' = 'white'
   ;
   value $FW
   'TEXT 1' = 'normal'.
   'TEXT 2' = 'bold'
   ;
run;.
 .
proc tabulate data=DAT s=[font=("arial")];.
  class UA;.
  classlev UA / style={foreground=$FD. fontweight=$FW. font=("arial")};.
  var X / style={font=("arial") fontweight=bold};.
  table UA, X;.
run;.

You don't show how  you are using SC but I suspect that you actually want 3 formats, foreground, fontsize for style overrides and the Unicode value to be displayed

 

Contributor
Posts: 54

Re: PROC FORMAT, font weight and ODS

[ Edited ]

ballardw, you beat me to the "Post" button by a few seconds. Smiley Happy  But you went through the trouble of finding the solution for me.  Thank you ballardw.  

Contributor
Posts: 54

Re: PROC FORMAT, font weight and ODS

Posted in reply to JohnSAScom

The solution is to create a new format specifying 'bold' and apply it in the CLASSLEV statement as another one of the already-existing style elements: 

 

ods escapechar='^';
 
proc format;
        value SC
                        0      ='^{style [foreground=red font_size=9pt] ^{unicode 25B6}}'
                0<-high='^{style [foreground=blue font_size=9pt] ^{unicode 25B2}}'
                low-<0 ='^{style [foreground=green font_size=9pt] ^{unicode 25BC}}';
run;
 
proc format;
        value $FD
        'TEXT 1' = 'white'
        'TEXT 2' = 'white';
 
        value $New
        'TEXT 2' = 'bold';
run;
 
proc tabulate data=DAT s=[font=("arial")];
  class UA;
  classlev UA / style={foreground=$FD. font=("arial") font_weight=$New.};
  var X / style={font=("arial") fontweight=bold};
  table UA, X;
run;
 
This will apply the bold font style only to the CLASSLEV value of 'TEXT 2', as intended. 
 
Thank you ballardw for your help. 
 
P.S. You can use either the {} or the [] with the style statement.  For example, either style={font=("arial") fontweight=bold} or style=[font=("arial") fontweight=bold] would work. 
☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 352 views
  • 2 likes
  • 2 in conversation