BookmarkSubscribeRSS Feed
kz_
Quartz | Level 8 kz_
Quartz | Level 8
In this series plot example (http://robslink.com/SAS/ods2/aaaindex.htm), the markers/colors are the same for both groups. I am trying to get different markers for the different groups.

I do realize that there are SAS examples - like the one I tried to copy. I was hoping that comment would get me something other than a reference to SAS documentation, which I usually check first.
12 REPLIES 12
kz_
Quartz | Level 8 kz_
Quartz | Level 8

I am trying to make a plot where the lines have different colors for each group (achieved with seriesplot and group) and there is some kind of marker to indicate whether the trend is increasing or decreasing (not achieved). 

 

I would like to use markers because the trends are subtle and not necessarily obvious on the plot (even though for this data an increase of 1 or 2% is important.) I tried using the linepatterngroup statement, but the line patterns that SAS automatically chose are hard to distinguish. 

 

Here is what I have: 

proc template;
  define statgraph groupgraph;
    begingraph / subpixel=on;
      entrytitle 'TITLE';
      layout overlay / xaxisopts=(display=(ticks tickvalues) label="Month")
	                         yaxisopts=(griddisplay=on linearopts=(viewmax=0.30) label="% of monthly x") ;
        seriesplot x=mo y=mo_perc / group=l_group name='a' lineattrs=(thickness=2) 
                  smoothconnect=true linecolorgroup=l_group linepatterngroup=trend_mo;
		
		scatterplot x=mo y=mo_perc / group=trend_mo name='b' markerattrs=(symbol=(circlefilled starfilled));
		
		layout gridded / halign=right valign=top columns=2 columngutter=5;
          discretelegend 'a' / title='Group' type=linecolor location=outside 
                        across=4 halign=left valign=bottom;
          discretelegend 'b' / title='Trend' location=outside 
                        across=4 halign=left valign=bottom itemsize=(linelength=30);
	 endlayout; endlayout; endgraph; end;
run;

The error after the markerattrs statement is: 

ERROR 22-322: Expecting a name.
ERROR 200-322: The symbol is not recognized and will be ignored.
 
 
proc template;
  define statgraph symbolchange;
    begingraph;
      layout overlay;
        scatterplot y=height x=weight /
          markerattrs=(symbol=circlefilled);
      endlayout;
    endgraph;
  end;
run;
I generally find the limited examples in SAS documentation to be frustrating since I find examples more helpful than the syntax statements. 
Reeza
Super User

Is there a specific reason you're using SGTEMPLATE and not just SGPLOT?

If you use SGPLOT, use a discrete data attribute map. 

https://documentation.sas.com/doc/en/vdmmlcdc/8.11/grstatproc/n16ad7597ctbm3n1x9pvpeo5g4gx.htm

 

Here's a better source of examples for base graphics:

http://robslink.com/SAS/ods2/aaaindex.htm

 

I'm assuming you also know to reference the Examples section in the documentation?

 


@kz_ wrote:

I am trying to make a plot where the lines have different colors for each group (achieved with seriesplot and group) and there is some kind of marker to indicate whether the trend is increasing or decreasing (not achieved). 

 

I would like to use markers because the trends are subtle and not necessarily obvious on the plot (even though for this data an increase of 1 or 2% is important.) I tried using the linepatterngroup statement, but the line patterns that SAS automatically chose are hard to distinguish. 

 

Here is what I have: 

proc template;
  define statgraph groupgraph;
    begingraph / subpixel=on;
      entrytitle 'TITLE';
      layout overlay / xaxisopts=(display=(ticks tickvalues) label="Month")
	                         yaxisopts=(griddisplay=on linearopts=(viewmax=0.30) label="% of monthly x") ;
        seriesplot x=mo y=mo_perc / group=l_group name='a' lineattrs=(thickness=2) 
                  smoothconnect=true linecolorgroup=l_group linepatterngroup=trend_mo;
		
		scatterplot x=mo y=mo_perc / group=trend_mo name='b' markerattrs=(symbol=(circlefilled starfilled));
		
		layout gridded / halign=right valign=top columns=2 columngutter=5;
          discretelegend 'a' / title='Group' type=linecolor location=outside 
                        across=4 halign=left valign=bottom;
          discretelegend 'b' / title='Trend' location=outside 
                        across=4 halign=left valign=bottom itemsize=(linelength=30);
	 endlayout; endlayout; endgraph; end;
run;

The error after the markerattrs statement is: 

ERROR 22-322: Expecting a name.
ERROR 200-322: The symbol is not recognized and will be ignored.
 
 
proc template;
  define statgraph symbolchange;
    begingraph;
      layout overlay;
        scatterplot y=height x=weight /
          markerattrs=(symbol=circlefilled);
      endlayout;
    endgraph;
  end;
run;
I generally find the limited examples in SAS documentation to be frustrating since I find examples more helpful than the syntax statements. 

 

 

Reeza
Super User
I've moved your question (albeit out of order) to the Graphics forum - you've been posting in the new user forum.
Hopefully someone else can answer your question, I don't know the answer within SGTEMPLATE but do within SGPLOT, ergo my suggestion.



kz_
Quartz | Level 8 kz_
Quartz | Level 8
Can you suggest how to do it in sgplot then? The example you suggested only has two groups, so I don't understand how to use it. The marker color and line color match - i.e., they aren't distinguishing separate things.

I need a plot with two sets of groups. One has seven classes and the other has two. They are not nested.
Reeza
Super User
Did you look at the discrete attribute maps example - the very first link I included?
ballardw
Super User

@kz_ wrote:
In this series plot example (http://robslink.com/SAS/ods2/aaaindex.htm), the markers/colors are the same for both groups. I am trying to get different markers for the different groups.

I do realize that there are SAS examples - like the one I tried to copy. I was hoping that comment would get me something other than a reference to SAS documentation, which I usually check first.

The linked page shows 4 series plots. Which one? None of those creates the same color for" both groups" unless possibly you are using gray-scale style and can't tell the "colors" apart. None of those examples use Proc template and Sgrender either. So, what code are you using?

 

 

kz_
Quartz | Level 8 kz_
Quartz | Level 8
The reason for the confusion is that I am using two sets of groups. That is why I want different line colors AND different markers.

In the example series plot, there is a pink line with pink markers and a blue line with blue markers.

In the plot that I am trying to create there will be 7 or 8 lines of different colors (first group). Then I want two different sets of markers on the lines to indicate the second group, i.e., the groups aren't nested.

I got SAS to this by showing one group with a dashed line and the other group with solid lines. Unfortunately the way SAS prints the dashed line doesn't aid much in distinguishing the groups. That is why I wanted to try for markers.
GraphGuy
Meteorite | Level 14

Being "old school" I would plot the lines, and then annotate the markers (using data step logic when you create the annotate dataset, to control which markers to use).

kz_
Quartz | Level 8 kz_
Quartz | Level 8
Also, I posted the example code that I used in the question. I didn't use the code in that example, I referenced it because someone else suggested it above.
JeffMeyers
Barite | Level 11

Here's how to setup an attribute map in GTL using the example you listed earlier:

ods path WORK.TEMPLAT(UPDATE) SASHELP.TMPLMST (READ);
proc template;
  define statgraph symbolchange;
    begingraph;
      discreteattrmap name="attrs" / ignorecase=true DISCRETELEGENDENTRYPOLICY=ATTRMAP;
           value 'F' / lineattrs=(color=red pattern=1) markerattrs=(symbol=triangle color=blue);
           value 'M' / lineattrs=(color=blue pattern=2) markerattrs=(symbol=triangle color=red);
      enddiscreteattrmap;
      discreteattrvar attrvar=_attrs_ var=sex attrmap="attrs" ; 
      layout overlay;
        seriesplot y=height x=weight / group=_attrs_ name='a';
        scatterplot y=height x=weight / group=_attrs_ name='b';
        mergedlegend 'a' 'b'/ location=inside autoalign=(bottom);
      endlayout;
    endgraph;
  end;
run;

ods graphics / reset;
proc sgrender data=sashelp.class template=symbolchange;
run;

The discreteattrmap block is similar to a proc format section, but for each value you list out you can set the individual style elements (markerattrs, lineattrs, etc.).  You then setup a temporary variable with discreteattrvar that gets mapped to the variable that contains the values, and use that temporary variable in a GROUP option in your graph statements.

If you need the style to be based on two different variables (for lines and markers) there are two options.  First is to make two different attribute maps (named differently) and assign them to your series and scatter plot statements individually.  The second option is to make a new variable in your dataset with the unique combinations of the two variables (e.g. A and B = 1, A and C=2, B and C=3) and use the new variable in the attribute map.

 

In the above example I used a merged legend to combine the series and scatter plot legends together to get the appropriate legend that shows lines and markers together.  There's supposed to be a way that you can directly feed an attribute map into a legend but I haven't been able to get it to work so there could be a bug there.

whs278
Quartz | Level 8

Hi, I was also looking for a quick way to get different markers for different groups in PROC SGPLOT and found this.

 

 

ods graphics on / attrpriority=none;

proc sgplot data=sashelp.iris;
   title 'Fisher (1936) Iris Data';
   styleattrs datasymbols=(circlefilled squarefilled starfilled);
   scatter x=petallength y=petalwidth / group=species markerattrs=(size=5px);
run;

ods graphics / reset;

 

 

Source

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.3/statug/statug_odsgraph_sect013.htm

WarrenKuhfeld
Ammonite | Level 13

You might want to brush up on attribute priority. I hope you find this discussion helpful. We needed options for black and white, color, color but ok for color blind, etc, and so we came up with attribute priority.  http://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/statug/statug_odsgraph_sect050.htm

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 12 replies
  • 4777 views
  • 7 likes
  • 7 in conversation