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

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 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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:

 

 

 

vbox.png

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

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

PeterClemmensen
Tourmaline | Level 20

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:

 

 

 

vbox.png

dorian26
Calcite | Level 5

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

dorian26
Calcite | Level 5

ok it's working. Now i want to apply my format on freqrecherche and when i do it, there is a probleme

unison
Lapis Lazuli | Level 10

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

-unison
DanH_sas
SAS Super FREQ

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

dorian26
Calcite | Level 5
 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 7 replies
  • 4027 views
  • 1 like
  • 4 in conversation