BookmarkSubscribeRSS Feed
gzr2mz39
Quartz | Level 8
I'm using gplot to make some charts.
How do I specify that I always want a category in a categorical variable to be a specific color?
For example, if I have a variable x (with categories a,b,c) how do I specify that I always want c to be yellow?
If I use the symbol option then c may not be yellow if b is not plotted.
Thank you.
4 REPLIES 4
Cynthia_sas
SAS Super FREQ
Hi:
You may want to consider moving toward an approach like the one shown in this Tech Support note. http://support.sas.com/kb/24/874.html

It uses a SAS Macro program to guarantee that the ice cream flavors get the right color for the bar chart, even if there is no flavor in a particular group.

The key is specifying an explicit numbered PATTERN statement value in a macro program. Then the correct PATTERN statement is used for every group, so that strawberry is always pink, chocolate is always brown, etc, etc.

The other approach that folks use is to put a "dummy" obs into the data for every category or combination of category and by group. In this way, they ensure that there will be the right number of categories. See the program example below. SASHELP.CLASS only has 1 student -- a male in the age 16 group -- so by putting an extra observation for F in the dataset to graph, I can ensure that the bar for M uses the color in the second PATTERN statement.

cynthia
[pre]
ods listing;
proc freq data=sashelp.class;
title 'note that there are no F in Age 16';
where age in (14, 15, 16);
tables age*sex / list;
run;

** now, ADD an F observation with a very, very LOW value for the SUMVAR variable;
data class;
set sashelp.class end=eof;
where age in (14, 15, 16);
output;
if eof then do;
** make sure that age 16 has an obs for F;
name = 'extra';
sex = 'F';
height=.0001;
age = 16;
output;
end;
run;

proc sort data=class out=class;
by age;
run;

goptions reset=all;
pattern1 c=pink v=s;
pattern2 c=blue v=s;

proc gchart data=class;
title 'By Age #byval1';
by age;
vbar sex / sumvar=height patternid=midpoint;
run;
quit;

goptions reset=all;
[/pre]
gzr2mz39
Quartz | Level 8
Thank you.
I think the SAS macro program is a good idea:
http://support.sas.com/kb/24/874.html
Although I should be able to implement this approach do you have any other examples that don't involve "across by groups" (I'm just interested in maintaining patterns)?
Thanks.
Cynthia_sas
SAS Super FREQ
Hi:
Well, reading the documentation is always a good idea:
http://support.sas.com/documentation/cdl/en/graphref/63022/HTML/default/viewer.htm#/documentation/cd...

"Seeding" the data with all the combinations of groups/subgroups that you need would be good. Really understanding the possible combinations is critical to getting the PATTERN right. Understanding how PATTERNID can impact bar fills (PATTERNID=MIDPOINT, PATTERNID=SUBGROUP, PATTERNID=GROUP, etc).

Using Macro can help, but understanding the data will be the biggest help of all. Running some tests and making up some fake data to see how well your program works under different circumstances.

cynthai
ArtC
Rhodochrosite | Level 12
Although it specifically addresses LEGEND control, the paper
http://www2.sas.com/proceedings/sugi29/086-29.pdf also
discusses many of the same approaches.

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
  • 4 replies
  • 802 views
  • 0 likes
  • 3 in conversation