Hi all good morning
I would like to ask you how I can change symbols in SGPLOT procedure for different groups using scatter and series.
Thanks in advance
José Eduardo
If you have multiple groups on a plot, you can use the STYLEATTRS command in PROC SGPLOT to designate symbols for each group, and specify the desired symbols in the DATASYMBOLS= option.
Example:
proc sgplot data=sashelp.class;
styleattrs datasymbols=(diamond circle) datacontrastcolors=(red green);
scatter x=height y=weight / group=sex;
run;
Show us the code you are using. Paste your code into the code box (it pops up when you click on the "little running man" icon)
Repeating the instructions I gave earlier:
Paste your code into the code box (it pops up when you click on the "little running man" icon)
> I am not getting different symbols for groups.
Since we don't have your data, let's use data that we all have. The following creates some data for this example that (hopefully!) is similar to yours:
data Out;
set sashelp.stocks(keep=Stock Date Open where=(Date<'01JAN1991'd));
rename date=Time Open=mean;
run;
proc sort data=Out;
by Time Stock;
run;
/* write spline predictor to OUT2 data set in the PRED variable */
proc glmselect data=Out;
effect spl = spline(Time / basis=bspline knotmethod=equal(9));
class Stock;
model mean = spl | stock / selection=none;
output out=out2 pred=pred;
run;
Now let's graph the data. The following sets ATTRPRIORITY=NONE and lets the symbols, colors, and line styles change according to the ODS style.
ods graphics / AttrPriority=NONE;
proc sgplot data=Out2;
scatter y=mean x=time /group=Stock;
series y=pred x=time / group=Stock;
run;
The output is below. Note that the colors, symbols, and line patterns are different for all groups.
If you want to override the default colors or symbols or patterns, you can use the STYLEATTRS statement, as Paige suggested. You can override 1, 2, or all three attributes. In the following, I set all line patterns to SOLID, but specify colors and patterns for the markers and lines:
ods graphics / AttrPriority=NONE;
proc sgplot data=Out2;
styleattrs datalinepatterns=(solid)
datacontrastcolors=(SteelBlue DarkGreen DarkRed)
datasymbols=(CircleFilled TriangleFilled X);
scatter y=mean x=time /group=Stock markerattrs=( size=6 );
series y=pred x=time / group=Stock;
run;
Please read the article and study the examples. Hope this helps!
I used to create plots where different groups are displayed in different color and line patterns and therefore encountered the AttrPriority option in ODS GRAPHICS. I read the relevant introduction to that option given in SAS Help, but I was still rather confused on its utility. Could you please briefly explain it? Thank you!
Yes, happy to. Please see Attrs, attrs, everywhere: The interaction between ATTRPRIORITY, CYCLEATTRS, and STYLEATTRS in ODS gr...
and the links therein.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.