BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sanjay1
Obsidian | Level 7

Hi SAS experts,

Am tryng to create a proc template to add colors, and refering this template in proc sgrender procedurs.

But the colors which i have defined in the template are not working in sgrender. Please help. below is my code;

Is there is any other way to add colors.

 


data new;
input year name$ points;
datalines;
2006 a 900
2007 a 267
2008 a 290
2009 a 677
2006 b 1000
2007 b 2000
2008 b 2678
2009 b 677
2006 c 500
2007 c 400
2008 c 678
2009 c 877
2006 d 500
2007 d 600
2008 d 364
2009 d 466
2006 e 555
2007 e 654
2008 e 365
2009 e 645
2006 f
2007 f
2008 f
2009 f
run;

 

proc template;
define statgraph abc;
begingraph / datacolors=(CXE5CCFF CXFFCC99 CX64BEEB CXC4DA5A CX404040 );
layout overlay/
xaxisopts=(linearopts=(tickvalueformat=4.0 tickvaluesequence=(start=2006 end=2009 increment=1)))
yaxisopts=(griddisplay=on gridattrs=(pattern=dot)
linearopts=(tickvalueformat=(extractscale=true)));
seriesplot x=year
y=points / name= "ST3" group=name LINEATTRS = (THICKNESS = 3) display=all ;
discretelegend "ST3" / title="name" exclude=("f") ;

endlayout;
endgraph;
end;

proc sgrender data=new template=abc;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

You need to use the DATACONTRASTCOLORS option instead of the DATACOLORS option. The DATACOLORS option is for FILL colors, but you are using a SERIESPLOT. Line and markers get their colors from DATACONTRASTCOLORS.

 

Hope this helps!

Dan

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

What do you mean "are not working"?  I ran that code you have posted and I see a graph with colors.

sanjay1
Obsidian | Level 7

What I meant is the colors which i have declared in the template are not reffering in the graph, it is taking the by default colors.

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hmm, never used datacolors in my graphs.  From the docs it seems that only applies to fill colors - which would indicate to me bar charts and that type of thing rather than line color.  Generally speaking I setup my line information in a style template, then use that in geration of the output file - see below.  There are other methods to get color and such like, by adding lineattrs and linegroupattrs and such like.  Here is a site I sue a lot for graphs, have filtered for series plot:

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

(worth looking at the whole site though).

 

data new;
input year name$ points;
datalines;
2006 a 900
2007 a 267
2008 a 290
2009 a 677
2006 b 1000
2007 b 2000
2008 b 2678
2009 b 677
2006 c 500
2007 c 400
2008 c 678
2009 c 877
2006 d 500
2007 d 600
2008 d 364
2009 d 466
2006 e 555
2007 e 654
2008 e 365
2009 e 645
2006 f
2007 f
2008 f
2009 f
run;
proc template;
  define style Styles.mystyle; 
    parent=styles.listing;
    style GraphData1 from GraphData1 /
      ContrastColor=red
      Color=red
      MarkerSymbol="CircleFilled"
      Linestyle=1;
    style GraphData2 from GraphData2 /
      ContrastColor=black
      Color=black
      MarkerSymbol="TriangleFilled"
      Linestyle=1;
    style GraphData3 from GraphData3 /
      ContrastColor=orange
      Color=orange
      MarkerSymbol="SquareFilled"
      Linestyle=1;
    style GraphData4 from GraphData5 /
      ContrastColor=green
      Color=green
      MarkerSymbol="SquareFilled"
      Linestyle=1;
    style GraphData5 from GraphData5 /
      ContrastColor=purple
      Color=purple
      MarkerSymbol="SquareFilled"
      Linestyle=1;

  end;
run;
proc template;
define statgraph abc;
begingraph;
layout overlay/
xaxisopts=(linearopts=(tickvalueformat=4.0 tickvaluesequence=(start=2006 end=2009 increment=1)))
yaxisopts=(griddisplay=on gridattrs=(pattern=dot)
linearopts=(tickvalueformat=(extractscale=true)));
seriesplot x=year
y=points / name= "ST3" group=name LINEATTRS = (THICKNESS = 3) display=all ;
discretelegend "ST3" / title="name" exclude=("f") ;
endlayout;
endgraph;
end;
ods rtf file="s:\t.rtf" style=mystyle;
proc sgrender data=new template=abc;
run; 
ods rtf close;

sanjay1
Obsidian | Level 7

Thank you RW9 there is lot of information that helps me.

DanH_sas
SAS Super FREQ

You need to use the DATACONTRASTCOLORS option instead of the DATACOLORS option. The DATACOLORS option is for FILL colors, but you are using a SERIESPLOT. Line and markers get their colors from DATACONTRASTCOLORS.

 

Hope this helps!

Dan

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 2694 views
  • 0 likes
  • 3 in conversation