3

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.

Snorex
  • 904
  • 12
  • 29
  • 1
    I don't know that I have the complete answer, but I would recommend looking into CSS if you really want to maximize your code options. 9.4 (and to some extent 9.3) support importing CSS styles using a fairly large subset of CSS, directly in proc template. Cynthia Zender and Kevin Smith have multiple papers (and the latter, a book) on the topic. – Joe Aug 06 '15 at 21:03
  • If you have only one you could create a dynamic variable that held those options, but still not a great solution. You may want to cross post to communities.sas.com where soem SAS employees (Cynthia) may be able to comment directly. – Reeza Aug 06 '15 at 21:43
  • More likely Sanjay or Dan, in this case, I think. – Joe Aug 06 '15 at 21:55

1 Answers1

1

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...

Joe
  • 62,789
  • 6
  • 49
  • 67