BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JohnSAScom
Quartz | Level 8

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? 
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

5 REPLIES 5
ballardw
Super User

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.

JohnSAScom
Quartz | Level 8
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;
 
ballardw
Super User

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

 

JohnSAScom
Quartz | Level 8

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.  

JohnSAScom
Quartz | Level 8

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. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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