I'm using SAS. I'm creating box plots with 5 categories and I would like to choose a different, customized color for each category.
Here is my code :
data resultat.attrmapfreq;
retain id " freq" ;
input value $ fillcolor $;
datalines;
05 blue
01 red
02 magenta
03 maroon
04 olive
;
run;
proc sgplot data=resultat.Variables dattrmap=attrmapfreq ;
vbox MoyNotes / category=Freqrecherche group=Freqrecherche attrid=freq ;
format Freqrecherche Freqrecherche.;
run;
I already have random colors. Freqrecherche is numeric but how can i do ? Even if i create a new char variable it doesn't work. I do a format on Freqrecherche but can i use it and how ?
Please it's little bit important
See if you can use this as a template
data MyAttrMap;
length id $4 value FillColor $10;
input id value FillColor;
datalines;
MyID 13 Green
MyID 14 Gold
MyID 15 Red
;
proc sgplot data=sashelp.class dattrmap=MyAttrMap;
where age in (13, 14, 15);
vbox height / category=age group=age attrid=MyID;
run;
Result:
Hi and welcome to the SAS Community 🙂 Are you able to share the Variables data?
One thing you should correct at least is that you define your attribute map in the resultat library. But you reference an attribute map in the work library in your PROC SGPLOT Statement. You should put dattrmap=resultat.attrmapfreq there instead
See if you can use this as a template
data MyAttrMap;
length id $4 value FillColor $10;
input id value FillColor;
datalines;
MyID 13 Green
MyID 14 Gold
MyID 15 Red
;
proc sgplot data=sashelp.class dattrmap=MyAttrMap;
where age in (13, 14, 15);
vbox height / category=age group=age attrid=MyID;
run;
Result:
I tried like that :
data resultat.attrmapfreq;
length id $4 value Fillcolor $10;
input id value fillcolor ;
datalines;
freq 05 blue
freq 01 red
freq 02 magenta
freq 03 maroon
freq 04 olive
;
run;
proc sgplot data=resultat.Variables dattrmap=resultat.attrmapfreq ;
where Freqrecherche in (01, 02, 03, 04, 05);
vbox MoyNotes / category=Freqrecherche group=Freqrecherche attrid=freq ;
run;
it doesn't work. And there is an error " invlid attrid freq specified ". It's like there is no relation between my map and my plot
ok it's working. Now i want to apply my format on freqrecherche and when i do it, there is a probleme
Hello,
Can you explain what the problem is at the point in more detail? It is helpful to see code, log messages, etc. It’s confusing that you say “it’s working now” and also “there is a problem”
without seeing anything my guess is that the variable you want to apply this to is a character values but I can’t be sure.
-unison
The values in the VALUE column of the attrmap must be the formatted values. So, when you added your format, the values probably did not match up.
Hope this helps!
Dan
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.
Ready to level-up your skills? Choose your own adventure.