BookmarkSubscribeRSS Feed
josecorrente
Calcite | Level 5

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

10 REPLIES 10
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller
josecorrente
Calcite | Level 5
Hi pagemiller
Thank you for your reply. The problem is I am using scatter and series at the same plot (overlaid) and I am not get different symbols for grous. Using styleattrs it considers only the last symbol. The colors are ok. Do you have any suggestions to use different symbols? Thanks in advance.
PaigeMiller
Diamond | Level 26

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)

--
Paige Miller
josecorrente
Calcite | Level 5
Hi pagemiller
The code is:


proc sgplot data=Out11;
styleattrs datasymbols=(diamond circle ) datacontrastcolors=(black grey )
datalinepatterns=(solid dot );
scatter y=mean x=time /group=zygosity markerattrs=( size=6 );;
series y=pred x=time /group=zygosity markerattrs=( size=6 );
run;

The scatter plot is for the observations and the series is for a b-spline fit for these data.

Thanks in advance

PaigeMiller
Diamond | Level 26

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)

--
Paige Miller
Rick_SAS
SAS Super FREQ

> I am not getting different symbols for groups.

  1. First, you might want to read an article that describes the interaction between ATTRPRIORITY, CYCLEATTRS, and STYLEATTRS in ODS graphics. It might be that what you are seeing (or what you want to see) requires that you understand how these options interact.  
  2. It sounds like you might want to use ATTRPRIORITY=NONE, which enables the symbol to automatically change for different 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.

Rick_SAS_0-1748633847670.png

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;

 

Rick_SAS_1-1748634013483.png

Please read the article and study the examples. Hope this helps!

Season
Barite | Level 11

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!

Season
Barite | Level 11
Thank you so much for a response well more informative than I originally anticipated! Have a nice weekend!
josecorrente
Calcite | Level 5
Thank you very much for you reply. I will read the article and try in my data. Sincerely
Jose Eduardo

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is ANOVA?

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.

Discussion stats
  • 10 replies
  • 1593 views
  • 10 likes
  • 4 in conversation