BookmarkSubscribeRSS Feed
Forecaster
Obsidian | Level 7

I'm reading "Statistical graphics procedures by example" by Matange and Heath. I'm trying to modify the colors in the sgplot in the example below, but so far I have been not sucessful. Please see below for an example. I'm trying to change the color of "actual" by individual products.

data attrs;

input id $ value $ fillcolor $;

datalines;

actual A Blue

actual B Black

actual B Green

actual D Yellow

;

run;

proc sgplot data = sgbook.product_sales dattrmap=attrs;

  hbar product /response = actual barwidth=0.5 attrid=id;

  hbar product /response=predict barwidth=0.2;

run;

The above code does not work, how would I change the color for individualSGPlot4.png products.

5 REPLIES 5
DanH_sas
SAS Super FREQ

The problem is that the ATTRID is incorrect. The ATTRID should be the *value* in the ID column -- not the ID column name itself. The ID column is a reserved column name in an ATTMAP, so it does not need to be referenced. In your case, set attrid=actual, and you should get the correct result.

Forecaster
Obsidian | Level 7

@DanH, I changed the code following your suggestion, I still do not get the color change, Can you please help

data attrs;

input id $ value $ fillcolor $;

datalines;

ACTUAL A Blue

ACTUAL B Black

ACTUAL C Green

ACTUAL D Yellow

;

run;

proc sgplot data = sgbook.product_sales dattrmap=attrs;

  hbar product /response = actual  barwidth=0.5 attrid=actual;

  hbar product /response=predict barwidth=0.2;

run;

DanH_sas
SAS Super FREQ

The other issue is case-sensitivity. Sorry I missed that earlier. The ID value on the ATTRID option must match the case of the ID value in the ATTRMAP data set. Incidentally, We have added a couple of new columns to the ATTRMAP data set for SAS 9.4m3. One of those columns gives you the ability to turn off case-sensitivity.

Forecaster
Obsidian | Level 7

@DanH for some reason, I'm still not getting the right colors. I have changed the codes for easy replicability.

I'm running this code on SAS 9.3 (TS1M2)

data sales;

  input product $ actual predict;

  datalines;

  A 10 5

  B 12 15

  C 15 18

  D 13 20

  ;

run;

data attrs;

input id $ value $ fillcolor $;

datalines;

actual A blue

actual B black

actual C green

actual D yellow

;

run;

SGPlot24.png

proc sgplot data = sales dattrmap=attrs;

  hbar product /response = actual  barwidth=0.5 attrid=actual;

  hbar product /response=predict barwidth=0.2 ;

run;

DanH_sas
SAS Super FREQ

Sorry, I overlooked that you are not using a GROUP variable. Attrmaps only work when there is a GROUP active. For your example, you just need to use FILLATTRS=(color=<some color>) to control the color of the bars.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 2651 views
  • 3 likes
  • 2 in conversation