Data visualization with SAS programming

GTL: How using your own style elements (with their own names)?

Reply
Contributor
Posts: 43

GTL: How using your own style elements (with their own names)?

Hi,

This is a problem I already had 18 months ago.

http://communities.sas.com/message/29788#29788

At that time, Dan proposed me a solution but in my today’s case, that solution is not possible. My conclusion at that time was:

in fact, you can't use your own style elements (with their own names) to customize your result.

I received no deny but maybe there is a solution…

My today’s problem:

When using proc template, you can create any style element you'd like and give any name to that style element. The problem is that, if the style element is not having a referenced name, you can't use the style elements you created this way.

A little example will help...

proc template;

define statgraph contourplotparm;

   begingraph;

     LAYOUT LATTICE / COLUMNS=2 ROWS=2 ;

         layout overlay;

       contourplotparm x=height y=weight z=density /

         contourtype=fill nhint=12

           name="Contour" colormodel=threecolorramp;

       endlayout;

         layout overlay;

       contourplotparm x=height y=weight z=density /

         contourtype=fill nhint=16

           name="Contour" colormodel=threecolorramp;

       endlayout;

               layout overlay;

       contourplotparm x=height y=weight z=density /

         contourtype=fill nhint=20

           name="Contour" colormodel=threecolorramp;

       endlayout;

               layout overlay;

       contourplotparm x=height y=weight z=density /

         contourtype=fill nhint=24

           name="Contour" colormodel=threecolorramp;

       endlayout;

     endlayout;

   endgraph;

end;

run;

proc sgrender data=sashelp.gridded template=contourplotparm;

run;

That template is creating a 2*2 ceils graph. the same contourplotparm graph is reproduced in the four cells. As an option, I indicate COLORMODEL=threecolorramp (but this is the default).

The colors used for this graph (red / blue / white by default) are defined by a style element named threecolorramp. To modify the colors, you should use the colormodel option. The value of that option can only be a style element (colormodel=(options) is not possible as colormodel=style-element(options))

I'd like to use for each cell its own triplet of colors.

So, I run this second proc template.

proc template ;

define style toto ;

  parent=styles.statistical ;

  class threecolorramp1 /

     endcolor=CXD3D3D3

     startcolor=CXFFDAB9

     neutralcolor=CXF0E68C;

  class threecolorramp2 /

     endcolor=CXFFB6C1

     startcolor=CXFFFFF0

     neutralcolor=CX808000;

  class threecolorramp3 /

     endcolor=CXFFF8DC

     startcolor=CXD8BFD8

     neutralcolor=CX708090;

  class threecolorramp4 /

     endcolor=CXFFDEAD

     startcolor=CX6A5ACD

     neutralcolor=CX778899;

end;

quit;

(colors are selected randomly)

Creating those brand new style elements with their own names is not a problem: the log is clear and the style elements are created.

But you can't use them!

Replace in the first proc template the name of the style element threecolorramp by the names of the style elements you created (no problem here, the log is clear when running the proc template) but if you run the PROC SGRENDER, you’ll see that it's not functioning.

proc template;

define statgraph contourplotparm;

   begingraph;

     LAYOUT LATTICE / COLUMNS=2 ROWS=2 ;

         layout overlay;

       contourplotparm x=height y=weight z=density /

         contourtype=fill nhint=12

           name="Contour" colormodel=threecolorramp1;

       endlayout;

         layout overlay;

       contourplotparm x=height y=weight z=density /

         contourtype=fill nhint=16

           name="Contour" colormodel=threecolorramp2;

       endlayout;

               layout overlay;

       contourplotparm x=height y=weight z=density /

         contourtype=fill nhint=20

           name="Contour" colormodel=threecolorramp3;

       endlayout;

               layout overlay;

       contourplotparm x=height y=weight z=density /

         contourtype=fill nhint=24

           name="Contour" colormodel=threecolorramp4;

       endlayout;

     endlayout;

   endgraph;

end;

run;

ods listing style=toto ;

proc sgrender data=sashelp.gridded template=contourplotparm;

run;

I’m having, in my (French) log the following message:

WARNING: La référence du style threecolorramp1' est incorrecte. Ignorée.

WARNING: La référence du style threecolorramp2' est incorrecte. Ignorée.

WARNING: La référence du style threecolorramp3' est incorrecte. Ignorée.

WARNING: La référence du style threecolorramp4' est incorrecte. Ignorée.

The option COLORMODEL is only accepting a very short list of style elements as value (threecolorramp, threecoloraltramp, twocolorramp and twocoloraltramp).

proc template ;

define style toto ;

  parent=styles.statistical ;

  class threecolorramp /

     endcolor=CXD3D3D3

     startcolor=CXFFDAB9

     neutralcolor=CXF0E68C;

  class threecoloraltramp /

     endcolor=CXFFB6C1

     startcolor=CXFFFFF0

     neutralcolor=CX808000;

  class twocolorramp3 /

     endcolor=CXFFF8DC

     startcolor=CXD8BFD8 ;

  class twocoloraltramp /

     endcolor=CXFFDEAD

     startcolor=CX6A5ACD ;

end;

quit;

proc template;

define statgraph contourplotparm;

   begingraph;

     LAYOUT LATTICE / COLUMNS=2 ROWS=2 ;

         layout overlay;

       contourplotparm x=height y=weight z=density /

         contourtype=fill nhint=12

           name="Contour" colormodel=threecolorramp;

       endlayout;

         layout overlay;

       contourplotparm x=height y=weight z=density /

         contourtype=fill nhint=16

           name="Contour" colormodel=threecoloraltramp;

       endlayout;

               layout overlay;

       contourplotparm x=height y=weight z=density /

         contourtype=fill nhint=20

           name="Contour" colormodel=twocolorramp;

       endlayout;

               layout overlay;

       contourplotparm x=height y=weight z=density /

         contourtype=fill nhint=24

           name="Contour" colormodel=twocoloraltramp;

       endlayout;

     endlayout;

   endgraph;

end;

run;

ods listing style=toto ;

proc sgrender data=sashelp.gridded template=contourplotparm;

run;

Is there a way to add to the authorized list of style elements (since there is one) the style elements I create? (my real problem is more complicated than the example I’m proposing here… the number of cells of my graph is not limited to 4 and can be much higher)

I’ll send a wonderful present to the person who will find me the solution ;-)

Best regards

Sébastien Ringuedé

SAS Super FREQ
Posts: 925

GTL: How using your own style elements (with their own names)?

The solution to your problem is in SAS 9.3, which is due out in a few weeks :-). In SAS 9.3, we have a construct called an "attribute map". An attribute map enables you to associate visual attributes with discrete data values (DISCRETEATTRMAP) or ranges (RANGEATTRMAP). For your case above, you will be able to define a range attribute map for each contour, with the ability to set different ranges and colors for each one. Unfortunately, I do not have a GTL solution for you at SAS 9.2. The only possibility I know would be to render each contour separately and use ODS LAYOUT to lay them out in a grid. That way, you could change the color of the contours through the style between each rendering.

Hope this helps,

Dan

Contributor
Posts: 43

GTL: How using your own style elements (with their own names)?

Hi Dan and thanks for your anwser

I want a 9.3 right now ! even if 9.3 won't allow me to create and use my own style element (with their own names).

Now, an ODS LAYOUT solution is functionning but is much more complicated than a LATTICE / COLUMNS= ROWS=

with LATTICE, I don't have to deal with the size of each cells, with ODS LAYOUT, according to the number of rows and colums I want, I need to think a little more...

a little example (hope it'll help...)

proc template;

define statgraph contourplotparm2;

   begingraph;

         layout overlay;

       contourplotparm x=height y=weight z=density /

         contourtype=fill nhint=12

           name="Contour" colormodel=threecolorramp;

       endlayout

   endgraph;

end;

define style toto1 ;

  parent=styles.statistical ;

  class threecolorramp /

     endcolor=CXD3D3D3

     startcolor=CXFFDAB9

     neutralcolor=CXF0E68C;

end;

define style toto2 ;

  parent=styles.statistical ;

  class threecolorramp /

     endcolor=CXFFB6C1

     startcolor=CXFFFFF0

     neutralcolor=CX808000;

end;

quit;

OPTIONS NODATE NONUMBER;

TITLE;

ODS PDF FILE='test.pdf' STYLE=toto1 NOTOC;

ODS GRAPHICS / HEIGHT=12cm WIDTH=17cm;

ODS LAYOUT START WIDTH=21cm HEIGHT=29.7cm;

ODS REGION X=1cm Y=0cm WIDTH=17cm HEIGHT=12cm;

proc sgrender data=sashelp.gridded template=contourplotparm2;

run;

ODS PDF STYLE=toto2;

ODS REGION X=1cm Y=13cm WIDTH=17cm HEIGHT=12cm;

proc sgrender data=sashelp.gridded template=contourplotparm2;

run;

ODS LAYOUT END;

ODS PDF CLOSE;

best regards

Sébastien

PS : and if I find a definitive solution to my problem using ODS LAYOUT, you'll receive by email the wonderfull present...

Occasional Contributor
Posts: 18

Re: GTL: How using your own style elements (with their own names)?

As sébastien, i am searching to customized the color of the "ThreeColorAltRam" called by the "markercolorgradient" statement...

SAS Super FREQ
Posts: 1,145

Re: GTL: How using your own style elements (with their own names)?

You can customize the start, end and middle colors for the ThreeColorRamp, and the MarkerColorGradient will use it.

Now, you can create a whole new custom element called "Foo".  But you cannot have any GTL or SG procedure code honor this foreign element.  One exception is additional GraphDataXX elements.  Normally XX=1 to 12 are defined, You can create additional elements up to XX=99 and use them, as long as they are contiguous.

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