Use custom class instead of GraphValueText for textattrs option in PROC TEMPLATE?

410 Views Asked by At

Using SAS 9.3 and trying to adhere to DRY by defining a custom style and using it with multiple ENTRY statements throughout a PROC TEMPLATE's statgraph block.

Custom style:

proc template;
define style llama;
    parent=styles.fancyPrinter;
    style CustomFonts from GraphFonts /
        'GraphValueFont'=("<sans-serif>, <MTsans-serif>",25pt,italic)
    ;
    class foo from GraphValueText / 
        font = CustomFonts('GraphValueFont') 
        color = GraphColors('gtext');
end;
run;

and then opened by a style= option in an ODS statement. I try to use foo:

Entry halign=left "bar / 1000" / textattrs=foo;

but get the log message:

NOTE: The style element 'foo' in the option TEXTATTRS is invalid. The default will be used.

It works fine when the TEXTATTRS is set using a definition like this (but since I'm using it a bunch of times, it won't be DRY):

textattrs=GraphValueText(weight=bold size=16pt color=CX800080)

Also, I know ODS is reading the style definition, because if I do:

style GraphFonts from GraphFonts

and change the fonts, it'll impact the graphs.

1

There are 1 best solutions below

0
On

I don't have a good answer unfortunately for how to do this, though it's possible one exists.

What I do think is that GTL isn't completely listening to you. For example:

proc template;
define style llama;
    parent=styles.fancyPrinter;
    style CustomFonts from GraphFonts /
        'GraphValueFont'=("<sans-serif>, <MTsans-serif>",25pt,italic)
    ;
    style graphUnicodeText from GraphValueText / 
        color=red;
    style graphValueText from GraphValueText/
        color=green;
end;
run;

proc template;
  define statgraph entry;
    begingraph;
      layout overlay;

        entry halign=right "First entry statement" /
          valign=top textattrs=graphValueText;

        histogram weight;

        entry halign=right "Second entry statement" /
            textattrs=graphUnicodeText;

        entry halign=right "Third entry statement" /
          valign=bottom pad=(bottom=40px);

      endlayout;
    endgraph;
  end;
run;

ods _all_ close;
ods html file="c:\temp\test.html" path="" gpath="c:\temp\" style=llama;
proc sgrender data=sashelp.class template=entry;
run;
ods html close;

Notice you don't get any errors about GraphUnicodeText... but you also don't get any effect from it. My guess is that GTL is doing its work with only partial awareness of the style, and thus isn't able to always respect what you ask it to do.

My suggestion (at least until/unless Sanjay or Dan or similar can help you find a better one) is to use a macro variable and/or a dynamic variable for this purpose.

proc template;
define style llama;
    parent=styles.fancyPrinter;
    style CustomFonts from GraphFonts /
        'GraphValueFont'=("<sans-serif>, <MTsans-serif>",25pt,italic)
    ;
    style graphUnicodeText from GraphValueText / 
        color=red;
    style graphValueText from GraphValueText/
        color=green;
end;
run;

proc template;
  define statgraph entry;
    begingraph;
      layout overlay;
        dynamic entrycolor;

        entry halign=right "First entry statement" /
          valign=top;

        histogram weight;

        entry halign=right "Second entry statement" /
            textattrs=(color=entrycolor);

        entry halign=right "Third entry statement" /
          valign=bottom pad=(bottom=40px);

      endlayout;
    endgraph;
  end;
run;

ods _all_ close;
ods html file="c:\temp\test.html" path="" gpath="c:\temp\" style=llama;
proc sgrender data=sashelp.class template=entry;
dynamic entrycolor="red";
run;
ods html close;

You can then reuse entrycolor in multiple places in the template, and allow it to be specified by the user at runtime. It's not ideal, but it does work, at least...