BookmarkSubscribeRSS Feed
marieK
Obsidian | Level 7
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? 🙂

thank you for answers! Marie
5 REPLIES 5
GraphGuy
Meteorite | Level 14
Sorry, but you can't assign line colors, etc, like that 🙂

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!)
marieK
Obsidian | Level 7
thank you! But when i do a*b=by-variable then i get an overlay-Graph. And that i dont want 🙂 Any other idea? Message was edited by: marieK
DanH_sas
SAS Super FREQ
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]
marieK
Obsidian | Level 7
Hi Dan,


thanks for your tip! I will try it the next days!
ArtC
Rhodochrosite | Level 12
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

sas-innovate-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

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
  • 1218 views
  • 0 likes
  • 4 in conversation