The SAS Output Delivery System and reporting techniques

varying font between observations

Reply
Contributor
Posts: 23

varying font between observations

Hi all,

I'm trying to figure out if there's a way to vary some of the style attributes, such as font, between different observations of the same procedure output. Specifically, I'd like to do this with PROC PRINT, and maybe PROC REPORT, outputting to HTML, PDF, and possibly RTF.

I started by playing around with the "fontlist" macro found here: http://support.sas.com/documentation/cdl/en/lrcon/62753/HTML/default/viewer.htm#n04qo8tw2712qln1mzug...

I was trying to see what all of the actual fonts looked like, rendered in those specific typefaces, rather than just listing out the font information all in the same (default) typeface. I came up with a way to do it using a macro that makes separate PROC PRINT calls, one line at a time, but that seems kind of cumbersome.

So, does anyone know if it's possible to have style elements change attributes between different observations (or sets of observations) within the same procedure output?

Thanks!

Super User
Super User
Posts: 7,050

varying font between observations

Look at the last example on this page that does it using the TEMPLATE.

http://support.sas.com/rnd/base/new92/92odsmore.html

SAS Super FREQ
Posts: 8,866

Re: varying font between observations

Hi:

  Here's a simple example using PROC REPORT. All the change happens within the PROC REPORT code without using a template or a macro. Simple STYLE= overrides change the style of each row based on the value of the SEX variable on each observation.

cynthia

ods listing close;

ods pdf file='c:\temp\chgfont.pdf';

ods rtf file='c:\temp\chgfont.rtf';

ods html file='c:\temp\chgfont.html' style=sasweb;

  proc report data=sashelp.class nowd;

    column name sex age height weight;

          define name /display;

          define sex / display;

          define age / display;

          define height / display;

          define weight / display;

          compute sex;

            if sex = 'F' then do;

               call define(_row_,'style',"style={font_face='Helvetica' fontsize=18pt}");

            end;

      else do;

               call define(_row_,'style',"style={font_face='Courier New' fontsize=20pt}");

            end;

          endcomp;

run;

ods _all_ close;

Super User
Posts: 10,028

Re: varying font between observations

Posted in reply to Cynthia_sas

Cynthia .

Another way is to use Traffic Light Skill.  Just like change the color of font.

Firstly, use proc format make a format, then use it in proc print or proc report.

proc format;
value $ fmt
 'F'='20pt'
 'M'='10pt';
run;

ods html file='c:\temp\chgfont.html' style=sasweb;

  proc report data=sashelp.class nowd;
    column name sex age height weight;
          define name /display;
          define sex/display style={fontsize=$fmt.};
run;

ods html close;


Ksharp

Contributor
Posts: 23

Re: varying font between observations

Posted in reply to Cynthia_sas

Hi Cynthia,

Thanks for the helpful response! That is basically what I want, although not exactly. If you look at the "fontlist" macro in the link from my original post, I am trying to replace the PROC PRINT call at the end of the macro. What I would like to replace it with is basically something like either of the following, although neither of the below PROC REPORT calls do exactly what I'm looking for as-is.

proc report data=fonts2 center spanrows nowd style(report) = {font_size = 14pt} ;

column font fstyle fweight type ;

define font / display ;

define fstyle / display ;

define fweight / display ;

define type / display ;

compute font ;

    call define(_row_,'style/merge',"style={font_face='"||font||"'}");

    endcomp;

compute fstyle ;

    call define(_row_,'style/merge',"style={font_style='"||fstyle||"'}");

    endcomp;

compute fweight ;

    call define(_row_,'style/merge',"style={font_weight='"||fweight||"'}");

    endcomp;

run; quit;

proc report data=fonts2 center spanrows nowd style(report) = {font_size = 14pt} ;

column font fstyle fweight type ;

define font / display ;

define fstyle / display ;

define fweight / display ;

define type / display ;

compute font ;

    call define(_row_,'style/merge',"style={font_face='"||font||"' font_style='"||fstyle||"' font_weight='"||fweight||"'}");

    endcomp;

run; quit;

In both cases, the font face is rendered correctly, but the font style and font weight do not render at all. In addition, I get a whole bunch of errors like the following:

ERROR 22-322: Syntax error, expecting one of the following: a name, a format name, !, @, DYNAMIC,

              EXPRESSION, ITALIC, RESOLVE, ROMAN, SLANT, SYMGET, _UNDEFINE_, _UNDEF_, _UND_, |.

ERROR 76-322: Syntax error, statement will be ignored.

I've revised some of the values of FSTYLE and FWEIGHT so that they are all valid values (eg, ITALIC, ROMAN, etc), so that's not it. In case you're interested, I'm attaching the output from the first PROC REPORT call.

Attachment
Contributor
Posts: 23

Re: varying font between observations

Never mind. I had extra single quotes around the font style and font weight. It works now. Thanks again!

Ask a Question
Discussion stats
  • 5 replies
  • 342 views
  • 0 likes
  • 4 in conversation