Hi,
I have a problem having same color for each group when generating multiple figurs. Below is my program. I've also tried reset attrpriority=color, which didn't work neither in SAS studio.
proc format;
value Cat_raceeth 2='NON-H Caucasian' 3='NON-H African American' 4='NON-H Asian' 1= 'Hispanic' 5='Other/Unknow';
run;
data myattrmap;
id="myid"; value=1;
linecolor="B"; fillcolor="B";
textcolor="B"; textstyle="normal";
textweight="normal";
output;
id="myid"; value=2;
linecolor="R"; fillcolor="R";
textcolor="R"; textstyle="normal";
textweight="normal";
output;
id="myid"; value=3;
linecolor="Y"; fillcolor="Y";
textcolor="Y"; textstyle="normal";
textweight="normal";
output;
run;
ods listing gpath = '/Volumes/data/Output/Deliveries063022/Fig';
ods graphics/imagename="Test" imagefmt=png ;
title "Distribution of HbA1C lab result in the last year of follow-up";
title2 "Non-H Caucasian vs. Hispanic";
proc sgplot data=data.descriptives (where=(test_result_A1Clst between 4 and 14 and Cat_raceeth in (1, 2))) dattrmap=myattrmap;
histogram test_result_a1clst / group =Cat_raceeth binstart=4 binwidth=0.5 showbins transparency=0.7 attrid=myid;
run;
ods graphics/imagename="Test2" imagefmt=png;
title "Distribution of HbA1C lab result in the last year of follow-up";
title2 "Non-H Caucasian vs. Non-H Black";
proc sgplot data=data.descriptives (where=(test_result_A1Clst between 4 and 14 and Cat_raceeth in (2, 3))) dattrmap=myattrmap;
histogram test_result_a1clst / group =Cat_raceeth binstart=4 binwidth=0.5 showbins transparency=0.7 attrid=myid;
run;
ods graphics off;
Note from SAS:
NOTE: ODS statements in the SAS Studio environment may disable some output features.
The histogram ended up with blue and red for each figure.
Any suggestion would be helpful! Thanks.
Without seeing your data to be sure, I would say that the issue is that formatted values of your "cat_raceeth" group variable do not match the values in your attrmap data set. Also, the "value" column should be character, so you should put those values in quotes.
Hope this helps!
Dan
Good catch! But unfortunately, it didn't work when I fixed as you suggested. I guess the order of color is set by default and hard to change in SAS studio?
Sorry, just looking at this again. I see the VALUE in you attrmap is formatted into a string by your user-defined format. Therefore, the VALUE in the attrmap needs to be the strings from the format, not the number.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.