I have a dataset that I need to use to create a simple series plot - well a whole bunch based on the different crossings of the "by variables". I am able to do this but I received a comment on the lack of consistency in the color coding for the categorical variable in my "group = " option. For most plots, I have 5 distinct values in the variable listed in the "group = " option - thus, I will get 5 different plots for most "by groups". However, for several crossings of my "by group", I may have 3 or 4 distinct values for the "group = " option. This causes the color coding to get messed up. Is there a way for me to specify the color to be used for each series based on the value of the variable in my "group = " option? I looked around and apparently in GTL - there is the GraphDataN class that can control colors and other options for each "group"- however, I don't think this is what I am looking for since I want to control the color/marker options based on the value of the "group".
5 categories:
history - blue circle
prior forecast - red cross
high scenario - green star/"x"
mid scenario - brown triangle
low scenario - purple square
4 categories
history - blue circle
high scenario - red cross
mid scenario - green star/"x"
low scenario - brown triangle
3 categories
history - blue circle
prior forecast - red cross
blended scenario - green star/"x"
Basically, I want the color and marker to be consistent based on the "group=" variable.
Another idea, If your different graphs can be generated togetter (from the same dataset) with a BY variable, then using UNIFORM=GROUP will provide consistent group attributes.
PG
Which Proc (or other) are you using to plot the data?
proc sgplot v 9.2
If you are using version 9.3 you should look at Attribute maps. I think it does exactly what you want.
PG
I am using 9.2. We should be upgrading to 9.3 soon.
Another idea, If your different graphs can be generated togetter (from the same dataset) with a BY variable, then using UNIFORM=GROUP will provide consistent group attributes.
PG
This did the trick so far. I am still interested in knowing if we can control colors and marker attributes based on the value of the "group= " option.
I have this exact problem and would love to use the UNIFORM=GROUP option except that I need to generate a completely separate output file for each value of the BY Group. When I do it now it generates the separate plots per BY group as expected but into the same file. I need a separate RTF file per BY group. I'm using v9.2 and PROC SGPLOT. Is it possible to to do this?
The ODS RTF statement has an option called NEWFILE=BYGROUP that may do just what you need. It will add an index to the end of the filename you specify.
Hope this helps!
Dan
Thanks Dan! That did work as you promised though I'm not sure I'm going to be able to use it because I need more control over the individual elements of each outputted plot and will probably have to do the BY groups as individual macro calls. I'm feeling stuck though because I have the same problem as the original poster...I need to assign marker characters based on values in the data rather than those assigned sequentially by GraphValuex so they'll be consistent across graphs. Is there any way to do that?
As PGStats mentioned, attribute maps are THE way to do this at 9.3. However, at 9.2, you can also simulate this in GTL by using the GROUPINDEX option. I show a little example of this in the first installment of "Roses are red, violets are blue...". Take a look at that example and see if that helps you.
Thanks!
Dan
http://blogs.sas.com/content/graphicallyspeaking/2012/02/27/roses-are-red-violets-are-blue/
http://blogs.sas.com/content/graphicallyspeaking/2012/03/01/roses-are-red-violets-are-blue-part-2/
Yes! This worked great. Thanks a lot!
Hello Experts,
how do we create a plot using the set of data like below:
Category | element | value | date |
cat1 | a | 20 | Jan-10 |
cat1 | a | 30 | Feb-10 |
cat1 | a | 40 | Mar-10 |
cat1 | a | 25 | Apr-10 |
cat1 | b | 10 | Jan-10 |
cat1 | b | 15 | Feb-10 |
cat1 | b | 20 | Mar-10 |
cat1 | b | 25 | Apr-10 |
cat2 | c | 30 | Jan-10 |
cat2 | c | 35 | Feb-10 |
cat2 | c | 25 | Mar-10 |
cat2 | c | 50 | Apr-10 |
cat2 | d | 45 | Jan-10 |
cat2 | d | 50 | Feb-10 |
cat2 | d | 60 | Mar-10 |
cat2 | d | 55 | Apr-10 |
From above data we can see that , category "cat1" have two elements "a and b" , category "cat2" have two elements "c and d" and for all of them we have "values" and "date".
Que is how do we create plot which looks like this:
Motive is to see how category looks at an aggregated level along with how its elements are contributing. So above plot will be for "CAT1 and all its elements (here A and B)" and we will have same for "CAT2". That is only two output graphs.
Thanks,
Harshad M.
Try the following and see if it is what you want:
data sample;
input Category $ element $ value date $;
cards;
cat1 a 20 Jan-10
cat1 a 30 Feb-10
cat1 a 40 Mar-10
cat1 a 25 Apr-10
cat1 b 10 Jan-10
cat1 b 15 Feb-10
cat1 b 20 Mar-10
cat1 b 25 Apr-10
cat2 c 30 Jan-10
cat2 c 35 Feb-10
cat2 c 25 Mar-10
cat2 c 50 Apr-10
cat2 d 45 Jan-10
cat2 d 50 Feb-10
cat2 d 60 Mar-10
cat2 d 55 Apr-10
;
run;
proc sgplot data=sample;
by category;
series x=date y=value / group=element;
run;
if we also want to have category y2axis then I would add a line your code
proc sgplot data=sample;
by category;
series x=date y=value / group=element;
series x=date y=CAT_value/group=Category; /*here CAT_value is a variable having the value variable aggregated to the category level
so as to be able to plot category*/
run;
Thanks.
Harshad M.
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.