Data visualization with SAS programming

different symbol-colors for by-variable subgroups

Reply
Contributor
Posts: 41

different symbol-colors for by-variable subgroups

hi,

i did some series-plots with proc gplot and would like to change the color of the lines in dependency of the by-Variable value.

Like:

IF by-Variable EQ 'P01' THEN DO; symbol v=plus ci=black i=join; END;
ELSE IF by-Variable EQ 'P02' THEN DO; symbol v=plus ci=green i=join;END;
ELSE IF by-Variable EQ 'P02' THEN DO; symbol v=plus ci=red i=join;END;
ELSE IF by-Variable EQ 'P02' THEN DO; symbol v=plus ci=blue i=join;END;

Is that possible? And when yes, how? Smiley Happy

thank you for answers! Marie
SAS Employee
Posts: 963

Re: different symbol-colors for by-variable subgroups

Sorry, but you can't assign line colors, etc, like that Smiley Happy

With gplot, you set up the symbol statements with a number (n), such as symbol1 - symboln...

symbol1 v=plus ci=black i=join;
symbol2 v=plus ci=green i=join;
symbol3 v=plus ci=red i=join;
symbol4 v=plus ci=blue i=join;

proc gplot data=foo;
plot y*x=by-Variable;

Then the values of by-Variable (or whatever the variable name you use) are assigned to the symbol statements, in alpha/numeric order (there are a few caveats & tricks, but I won't get into them unless you bump into the problems that would require them!)
Contributor
Posts: 41

Re: different symbol-colors for by-variable subgroups

thank you! But when i do a*b=by-variable then i get an overlay-Graph. And that i dont want Smiley Happy Any other idea? Message was edited by: marieK
SAS Super FREQ
Posts: 862

Re: different symbol-colors for by-variable subgroups

Hey Marie,

Because you have SAS 9.2, there is another way you can approach this graph. The Graph Template Language (GTL) supports the concept of "style indexing". You can put your attributes into the style and add an index in your data to reference those style attributes. This index variable is specified on the GTL plot statements where supported. Here is a simple example:

[pre]
/* Create a new style from the listing */
/* style using my attributes */
proc template;
define style styles.mystyle;
parent=styles.listing;
style graphdata1 from graphdata1 /
contrastcolor = orange
linestyle=1;
style graphdata2 from graphdata2 /
contrastcolor = purple
linestyle=1;
end;
run;

/* Tell the LISTING destination */
/* to use my new style */
ods listing style=mystyle;

/* Add the style indexing to my data */
data mydata;
set sashelp.class;
if (sex="M") then index=1;
if (sex="F") then index=2;
run;

/* Sort the data by the BY-group variable */
proc sort data=mydata; by sex; run;

/* Define the series plot */
proc template;
define statgraph series;
begingraph;
layout overlay;
seriesplot x=weight y=height / group=sex index=index;
endlayout;
endgraph;
end;
run;

/* Render the graph */
proc sgrender data=mydata template=series;
by sex;
run;
[/pre]
Contributor
Posts: 41

Re: different symbol-colors for by-variable subgroups

Hi Dan,


thanks for your tip! I will try it the next days!
Valued Guide
Posts: 632

Re: different symbol-colors for by-variable subgroups

A paper that relates to the association of variables to SYMBOL statements can be found at:
http://www2.sas.com/proceedings/sugi29/086-29.pdf
Post a Question
Discussion Stats
  • 5 replies
  • 152 views
  • 0 likes
  • 4 in conversation