BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
user42
Calcite | Level 5

I'm trying to implement the solution given in the forum post Proc sgplot: plotting different colors and markers for several groups in a scatter plotbut my plot markers are not changing with group.  Here's my code:

 

* Create attribute map;
data plotattrs;
	retain id "myid";
	length value 3.0 markercolor $ 6 markersymbol $ 6;
	input value markercolor $ markersymbol $;
	datalines;
		1 red plus
		2 green x
	;
run;

* Plot data;
proc sgplot
		data = sashelp.iris
		dattrmap = plotattrs;
	scatter x = petallength y = petalwidth /
		group = species
  		attrid = myid;
run;

 

The plot that is generated represents group by color, but not by marker type:

 

sasPlot.png

 

 

How can I make the plot marker type vary with group like the marker color does?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

The value has to match the value of the group variable.

Try

data plotattrs;
	retain id "myid";
	length value $ 10 markercolor $ 6 markersymbol $ 6;
	input value markercolor $ markersymbol $;
	datalines;
		Setosa red plus
		Versicolor2 green x
      Virginica blue  diamond
	;
run;

* Plot data;
proc sgplot
		data = sashelp.iris
		dattrmap = plotattrs;
	scatter x = petallength y = petalwidth /
		group = species
  		attrid = myid;
run;

View solution in original post

6 REPLIES 6
ballardw
Super User

The value has to match the value of the group variable.

Try

data plotattrs;
	retain id "myid";
	length value $ 10 markercolor $ 6 markersymbol $ 6;
	input value markercolor $ markersymbol $;
	datalines;
		Setosa red plus
		Versicolor2 green x
      Virginica blue  diamond
	;
run;

* Plot data;
proc sgplot
		data = sashelp.iris
		dattrmap = plotattrs;
	scatter x = petallength y = petalwidth /
		group = species
  		attrid = myid;
run;
user42
Calcite | Level 5

Thank you-- I knew I was missing something basic.

ballardw
Super User

You may also want to consider using longer text fields by default for you options just so you don't do what I did and tryto stuff "diamond" into a 6 character field.

user42
Calcite | Level 5
Yeah, I actually caught that one. 🙂
Ksharp
Super User
ods graphics / attrpriority=none;
proc sgplot	data = sashelp.iris;
 styleattrs datacolors=(red yellow blue) ;
	scatter x = petallength y = petalwidth /
	jitter	group = species;
run;
user42
Calcite | Level 5

Thanks for this, Ksharp. I wasn't aware of the "styleattrs" statement in proc sgplot.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 1579 views
  • 1 like
  • 3 in conversation