I encounted this error when using multiple scatter statements in sgplot. When I use one scatter statement, the error disapper. Anyone know what caused the problem?
scatter x=xvar_j y=jiop1 / markerattrs= (symbol=circle color=black size=10);
scatter x=xvar_j y=jiop2 / markerattrs= (symbol=closedcircle color=blue size=10);;
scatter x=xvar_j y=jiop3 / markerattrs= (symbol=circle color=black size=10);
scatter x=xvar_j y=jiop4 / markerattrs= (symbol=closedcircle color=blue size=10);
xaxis VALUES= (0.5 to 4.5 by .5) label = "Treatment Group and Eye" ;
yaxis VALUES= (10 to 35 by 5) label = "IOP Value (mm Hg)";
REFLINE 0.5 2.5 /AXIS=x LABEL = ("Treatment Group (N=&num_trt1.)" "Control Group (N=&num_trt2.)") ;
format xvar_j indexdf.;
This works to change the marker color automatically for multiple scatter plots, each with different grouping and colors coming from the style template. But, specifying a color in the markerattrs option seems to override the differing colors that normally come from the style template. So I'm thinking that if you want GROUPing in multiple scatter statements, you may need to change the style template that you use for the graph. Another reason to consult with Tech Support unless you are comfortable with style templates. Grouped data values are handled by the GDATA1-GDATA12 style elements.
proc sgplot data=sashelp.heart;
where cholesterol gt 300 and weight ge 125;
title 'Group and change Marker';
scatter x=ageatdeath y=cholesterol / group=sex
markerattrs= (symbol=circle size=5) name='sc_ch';
scatter x=ageatdeath y=weight / group=bp_status
markerattrs= (symbol=circlefilled size=5) name='sc_wt' y2axis;
keylegend 'sc_ch' 'sc_wt';
In SAS/GRAPH, this can be easily done by using 4 SYMBOL statements. But in ODS Graphics, it's not straight forward....i still prefer to use SAS/GRAPH in many cases. But I'm trying to reproduce many different types of figures i produced in SAS/GRAPH in ODS Graphics. Will post more questions later-on.
You can use the DATTRMAP= option on the PROC SGPLOT statement to define a discrete atrribute map.
For an example, see Specify the colors of groups in SAS statistical graphics - The DO Loop
With SAS 9.3, you can use the DATTRMAP as suggested by Rick. In this case, you can specify which group VALUE should get which marker symbol or color.
With SAS 9.2, you will need to define a new style in which you can replace the symbol and color values for GraphData1-N to the ones you want. An easy way to do this is to use the MODSTYLE macro. See Graphically Speaking article on this topic.
Coming with SAS 9.4 is a way to set group colors, symbols and line patterns in the procedure syntax itself.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.