BookmarkSubscribeRSS Feed
CHRISSY
Calcite | Level 5

Hello, I am using SAS 9.3.  In the code below for a non-grouped chart, I would like to color the bar for "Jane" differently than all the other bars on the graph.  If possible, I would also like to color the marker associated with "Jane" a different color than the other markers.  Also, if possible, I would like to have the tick value of  "Jane" on the xaxis to stand out somehow, maybe bold or different color. If different colors is not an option then how can I place a refline on the xaxis for "Jane".  Basically I need a way to make "Jane" stand out on the graph from all the other names on the xaxis.  My real data is not grouped and the values on the xaxis are text values.

I have tried using an attribute map to change the bar color, but that does not seem to work.  Please see my code below.  Thank you!

data attrmap;

  id='myid'; value='Jane'; fillcolor='orange'; output;

run;

proc sgplot data=sashelp.class

                 dattrmap=attrmap;

  vbar name / response = height

                    attrid = myid

                    name = 'bar'

                    legendlabel= 'Height';

  vline name /  response = weight

                     name = 'line'

                     legendlabel = 'Weight'

                     y2axis

                     markers

                     markerattrs=(symbol=circlefilled color=mor) 

                     lineattrs=(color=mor);

  xaxis display=(nolabel);

  yaxis grid

           label = 'Height'

           offsetmin=0

           offsetmax=0

           thresholdmax = 1

           thresholdmin = 1; 

  y2axis label = 'Weight'

            offsetmin=0

            offsetmax=0

            thresholdmax = 1

            thresholdmin = 1;

run;

1 REPLY 1
Jay54
Meteorite | Level 14

You can do this one of two ways.  The simplest one is to create a group column with a name say "ID".  Assign "Jane" to have ID=1, and all others as ID=2.  Then assign GROUP=id in VBar or other statements.  This will also work with overlaid scatters. Colors will come from style.  With SAS 9.4, you can use STYLEATTRS to assign the colors.

Or, you can separate "Jane" into a different variable "Name2", and make "Jne" from initial variable to missing.  Now use two VBAR statements, one fowith Name1, one with Name2.  Now you can assign the specific color (or other) attributes. to each statement.  This will also work with overlaid scatters, you just need two VBars and two Scatters.

Attrmaps work ONLY with groups. There is no way to change just one tick value to have a different color.  But you can use SGAnnotate to do that.

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
  • 1 reply
  • 1948 views
  • 1 like
  • 2 in conversation