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

Using SAS 9.3 and trying to stick to DRY by defining a custom style and using it with multiple ENTRY statements in the statgraph PROC TEMPLATE 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 with the style = command in the ODS statement. I am trying to use foo:

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

      

but get the log message:

NOTE. The style element 'foo' in the TEXTATTRS option is not valid. The default value will be used.

It works great when TEXTATTRS is given using a definition like this (but since I use it multiple times, it won't DRY):

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

      

Also, I know that ODS reads the style definition, because if I do this:

style GraphFonts from GraphFonts

      

and change the fonts, it will affect the graphics.

+3


source to share


1 answer


I do not have a good answer, unfortunately, how to do this, although it is possible.

I think GTL is not 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;

      

Note that you have no errors in the GraphUnicodeText ... but you are also not getting any effect from it. My guess is that GTL does its job with only partial style awareness and therefore cannot always respect what you ask for it.



My suggestion (at least until Sanjay or Dan or the like helps you find the best one), use a macro and / or dynamic variable for this.

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 set by the user at runtime. It's not perfect, but it works, at least ...

+1


source







All Articles