Data visualization with SAS programming

TEMPLATE, needleplot, group, color error

Reply
Frequent Contributor
Posts: 83

TEMPLATE, needleplot, group, color error

I am receiving the following error:

 

2586 proc template ;
2587 define style Styles.MyDefault ;
2588 parent = Styles.Default ;
2589 style GraphData1 from GraphData1
2590 / color = white
2591 ;
2592 style GraphData2 from GraphData2
2593 / color = blue
2594 ;
2595 style GraphData3 from GraphData3
2596 / color = green
2597 ;
2598 end ;
NOTE: Overwriting existing template/link: Styles.MyDefault
NOTE: STYLE 'Styles.MyDefault' has been saved to: SASUSER.TEMPLAT
2599 run ;
NOTE: PROCEDURE TEMPLATE used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


2600
2601 proc template ;
2602 define statgraph needle ;
2603 begingraph ;
2604 layout overlay / cycleattrs = true ;
2605 needleplot x = AA
2606 y = y
2607 / group = BindingLevel
2608 index = binding
2609 lineattrs = ( color = MyDefault )
---------
772
ERROR 772-580: Syntax error: expecting a constant or a dynamic.
2610 ;
2611 endlayout ;
2612 endgraph ;
2613 end ;
WARNING: Object will not be saved.
2614 run ;
NOTE: PROCEDURE TEMPLATE used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

WARNING: Errors were produced.
NOTE: The SAS System stopped processing this step because of errors.

 

I would appreciate any reference or help.

 

Thank you,

 

Kevin

Super User
Super User
Posts: 7,942

Re: TEMPLATE, needleplot, group, color error

Posted in reply to KevinViel

This post may help you:

https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/ERROR-772-580-Syntax-error-expecting-a-con...

 

If not then I would suggest writing an SGPLOT of what you want - take the example from this excellent blog (keep the link there are many many examples of every type of graph - very useful):

http://blogs.sas.com/content/graphicallyspeaking/?s=needleplot

 

Once you have the sgplot statement, then use the option tmplout="c:\test.txt"...

This will create a text file with the GTL template code.  I generally find its easier to get the template code generated from sgplot or one of the others, rather than trying to work it out from scratch.

Super Contributor
Posts: 256

Re: TEMPLATE, needleplot, group, color error

Posted in reply to KevinViel

Hello Kevin,

 

It seems like you want to use the three colours white, blue and green in your graph? One way to achieve this is to first, remove the code "lineattrs = ( color = MyDefault )". That is why you are getting the error.

 

i.e. use this:

 

proc template ;
  define statgraph needle ;
    begingraph ;
      layout overlay / cycleattrs = true ;
        needleplot x = AA y = y / group = BindingLevel index = binding;
      endlayout;
    endgraph ;
  end ;
run;

 

* Use the code below, before your SGRENDER statement to map to the MyDefault Style that you created;


ods listing style = styles.MyDefault;

 

 

 

 

Another option to get the exact colours that you want is to use attribute maps, and an example is on this blog:

 

http://blogs.sas.com/content/graphicallyspeaking/2013/04/06/attributes-map-2/

 

Thanks.

 

 

Super Contributor
Posts: 256

Re: TEMPLATE, needleplot, group, color error

Hi Kevin,

 

Actually, I've just seen that for the Needleplot you will also need to create a new "MyDefault" template, and use contrastcolor instead of color because that is what controls the colors of the lines. You may want to use another color instead of white too, so that you can see the first group. Please see below for an example.


proc template ;
  define style Styles.MyDefault ;
    parent = Styles.Default ;
      style GraphData1 from GraphData1
      / contrastcolor = white;
      style GraphData2 from GraphData2
      / contrastcolor = blue;
      style GraphData3 from GraphData3
      / contrastcolor = green;
end ;
run;

Frequent Contributor
Posts: 83

Re: TEMPLATE, needleplot, group, color error

So my updated code is:

 

data FVIII ;
  do AA = 1 to ( 2351 - 8 ) ;
    binding = ranbin( 1

                    , 2
                    , 0.1
                    ) ;

    if binding = 0
    then
      do ;
         binding + 1 ;
         BindingLevel = " " ;
         Y = 0 ;
         output ;
      end ;
     else if binding = 1
     then
       do ;
          binding + 1 ;
          BindingLevel = "<=WB" ;
          Y = 0.5 ;
          output ;
       end ;
      else if binding = 2
      then
        do ;
           binding + 1 ;
           BindingLevel = "<=SB" ;
           Y = 1 ;
           output ;
        end ;
  end ;
run ;

 

proc template ;
  define style Styles.MyDefault ;
    parent = Styles.Default ;
    style GraphData1 from GraphData1
        / contrastcolor = white
          ;
    style GraphData2 from GraphData2
        / contrastcolor = blue
        ;
    style GraphData3 from GraphData3
        / contrastcolor = green
        ;
  end ;
run ;

 

proc template ;
  define statgraph needle ;
    begingraph ;
      layout overlay / cycleattrs = true ;
      needleplot x = AA
                 y = y
               / group = BindingLevel
                 index = binding
                 lineattrs = ( pattern = solid )
                 ;
      endlayout ;
    endgraph ;
  end ;
run ;

 

ods listing style = styles.MyDefault ;

 

proc sgrender data     = FVIII
              template = needle
              ;
run ;

 

The colors of the lines (needles) are not changing.  I added white instead of 0 as an exploration, since I have not yet learned how to control the range of the axis.  

 

Originally, I was using ODS HTML so that I could produce .gifs.

 

Thank you,

 

Kevin

SAS Super FREQ
Posts: 939

Re: TEMPLATE, needleplot, group, color error

Posted in reply to KevinViel

Your BindingLevel variable is getting truncated such that you are not getting all of your group values. Add this line after the DATA statement:

 

LENGTH BindingLevel $ 4;

 

 

Frequent Contributor
Posts: 83

Re: TEMPLATE, needleplot, group, color error

Oh man!  Rookie mistake.  That's what I get for working in the evening...

 

Thank you to everyone who helped.  The reason I wanted to use the TEMPLATE over the SGPLOT procedure was to gain experience and I planned to move to a lattice layout.

 

Thank you,

 

Kevin

Frequent Contributor
Posts: 83

Re: TEMPLATE, needleplot, group, color error

Posted in reply to KevinViel

This looks good.  I think I may be able to add this to my PharmaSUG (May 2016) paper to compliment or improve upon the GMAP and ANNOTATE approach.  I can acknowledge some of the contributors to this thread, but if the others would like to be included, then please email your names.

 

Thank you,

 

Kevin

Super Contributor
Posts: 256

Re: TEMPLATE, needleplot, group, color error

Posted in reply to KevinViel

As Dan mentioned, please update the length of the bindingLevel variable. Once you do this you will get a plot similar to the attachment below.

 

If you still want to produce HTML and .gifs then you can replace the ODS listing code with the code below.

 

ods graphics / reset = all imagefmt = gif;
ods html style = styles.MyDefault;

 

Below is a reference for controlling the axis in layout overlay (it's the SAS 9.2 version but will work in 9.3 and 9.4). The linearopts option within the yaxisopts option will help you to control the range.

 

http://support.sas.com/documentation/cdl/en/grstatgraph/63878/HTML/default/viewer.htm#p1iii02qgue4et...

 

I was wondering, do you need to use the index option in your plot? If not then you could create the graph more easier using SGPLOT.

 

Thank you.

 


SGRender1.gif
SAS Super FREQ
Posts: 1,171

Re: TEMPLATE, needleplot, group, color error

Posted in reply to KevinViel

Kriss is right.  You cannot set the LINEATTRS COLOR suboption to the name of a style (MyDefault).  You can set it to a color value (a SAS color name like Black or Blue or CXffafbf).   Please see software documentation.

Frequent Contributor
Posts: 83

Re: TEMPLATE, needleplot, group, color error

Posted in reply to Sanjay_SAS

Could you be more specific about the location in the "documentation"?  I have "Statistical Graphics in SAS".  I had to modify a program in my day job so I was finally able (forced) to use the TEMPLATE and SGRENDER procedures.  Spending hours trying to "break" into this, I came across the online documentation for the needle plot.  The lattice approach seemed interesting, so I thought I might attempt it for an alternative (updated) approach to GMAP, which is the topic of my upcoming PharmaSUG.  I use the SAS System as a bioinformatics tool.  GMAP provides a useful figure, but not publication quality.  FWIW, I was told that I might be relieved of the task of updating the program at work as they might farm it over to the R programmers.

Frequent Contributor
Posts: 83

Re: TEMPLATE, needleplot, group, color error

Posted in reply to KevinViel

Interestingly, in v9.3 using Windows 10, the GraphData4 appears to ignore the contrastcolor, but honors the linestyle:

 

 

data FVIII ;
  length BindingLevel $ 4 ;
  do AA = 1 to ( 2351 - 8 ) ;
    binding = ranbin( 1
                    , 2
                    , 0.1
                    ) ;
    if binding = 0
    then
      do ;
         binding + 1 ;
         BindingLevel = " " ;
         Y = 0 ;
         output ;
      end ;
     else if binding = 1
     then
       do ;
          binding + 1 ;
          BindingLevel = "<=WB" ;
          Y = 0.5 ;
          output ;
       end ;
      else if binding = 2
      then
        do ;
           binding + 1 ;
           BindingLevel = "<=SB" ;
           Y = 1 ;
           output ;
        end ;
  end ;

 

  BindingLevel = "<=ZZ" ;
  binding = 99 ;
  Y = 1 ;

  do AA = AA to ( 2351 ) ;
    output ;
  end ;

run ;


proc template ;
  define style Styles.MyDefault ;
    parent = Styles.Default ;
    style GraphData1 from GraphData1
        / contrastcolor = white
          linestyle = 1
          ;
    style GraphData2 from GraphData2
        / contrastcolor = blue
          linestyle = 1
          ;
    style GraphData3 from GraphData3
        / contrastcolor = red
          linestyle = 1
          ;
    style GraphData4 from GraphData4
        / contrastcolor = grey
          linestyle = 9
          ;
  end ;
run ;

 

proc template ;
  define statgraph needle ;
    begingraph ;
      layout overlay / cycleattrs = true ;
        needleplot x = AA
                   y = y
                 / group = BindingLevel
                   index = binding
                   ;
      endlayout ;
    endgraph ;
  end ;
run ;

GOptions Reset = All
         HOrigin = 0 in
         VOrigin = 0 in
         VSize = 6 in
         HSize = 8 in
         ;

 

ODS Graphics
  / Reset = All
    ImageFmt = gif
    AntiAliasMax = 2400

    ;

 

ODS Listing Close ;
ODS NoResults ;

 

ODS HTML Body = "E:\My SAS Files\9.3\SAS Listings\waste.HTML"
         GPath = "E:\My SAS Files\9.3\SAS Listings\"
         Style = styles.MyDefault
         ;

 

proc sgrender data = FVIII
              template = needle
              ;
run ;

 

ODS Listing ;
ODS Results ;

ODS HTML Close ;

 

I would appreciate any corrections, references or suggestions.

 

Thank you,

 

Kevin

 

SAS Super FREQ
Posts: 1,171

Re: TEMPLATE, needleplot, group, color error

Posted in reply to KevinViel

You are using INDEX option and the value for the "<=ZZ" is 99.  So, you get the color you are requesting, probably 99 mod 4.  Also, you have many missing values for group.  I removed "INDEX" and used "INCLUDEMISSINGGROUP=False, skipped the last 4 observations that are causing the last needle to look thick and used the default LISTING destination. Added legend.

Here is what I get:

 

Needle.png

Frequent Contributor
Posts: 83

Re: TEMPLATE, needleplot, group, color error

Posted in reply to Sanjay_SAS

Great!  Thanks, Sanjay.  The final values are relevant, more will appear, but I wanted to demarcate them.

 

This is a great deal less work than GMAP and ANNOTATE.

 

Thanks,

 

Kevin

SAS Super FREQ
Posts: 1,171

Re: TEMPLATE, needleplot, group, color error

Posted in reply to KevinViel

I am not sure why you would use GMAP to create a needle plot.  Are you aware of the SGPLOT procedure?  Take a look at all the examples here:  http://blogs.sas.com/content/graphicallyspeaking/

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