Data visualization with SAS programming

Question about proc sg plot and group = option

Accepted Solution Solved
Reply
Contributor
Posts: 66
Accepted Solution

Question about proc sg plot and group = option

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.


Accepted Solutions
Solution
‎04-24-2012 02:37 PM
Respected Advisor
Posts: 4,606

Re: Question about proc sg plot and group = option

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

PG

View solution in original post


All Replies
SAS Employee
Posts: 967

Re: Question about proc sg plot and group = option

Which Proc (or other) are you using to plot the data?

Contributor
Posts: 66

Re: Question about proc sg plot and group = option

proc sgplot v 9.2

Respected Advisor
Posts: 4,606

Re: Question about proc sg plot and group = option

If you are using version 9.3 you should look at Attribute maps. I think it does exactly what you want.

PG

PG
Contributor
Posts: 66

Re: Question about proc sg plot and group = option

I am using 9.2.  We should be upgrading to 9.3 soon.

Solution
‎04-24-2012 02:37 PM
Respected Advisor
Posts: 4,606

Re: Question about proc sg plot and group = option

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

PG
Contributor
Posts: 66

Re: Question about proc sg plot and group = option

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.

Occasional Contributor
Posts: 17

Re: Question about proc sg plot and 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?

SAS Super FREQ
Posts: 889

Re: Question about proc sg plot and group = option

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

Occasional Contributor
Posts: 17

Re: Question about proc sg plot and group = option

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?

SAS Super FREQ
Posts: 889

Re: Question about proc sg plot and group = option

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/

Occasional Contributor
Posts: 17

Re: Question about proc sg plot and group = option

Yes!  This worked great.  Thanks a lot!

Contributor
Posts: 37

Re: Question about proc sg plot and group = option

Hello Experts,

how do we create a plot using the set of data like below:

Categoryelementvaluedate
cat1a20Jan-10
cat1a30Feb-10
cat1a40Mar-10
cat1a25Apr-10
cat1b10Jan-10
cat1b15Feb-10
cat1b20Mar-10
cat1b25Apr-10
cat2c30Jan-10
cat2c35Feb-10
cat2c25Mar-10
cat2c50Apr-10
cat2d45Jan-10
cat2d50Feb-10
cat2d60Mar-10
cat2d55Apr-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:

Sabg.PNG

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.

SAS Super FREQ
Posts: 889

Re: Question about proc sg plot and group = option

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;

Contributor
Posts: 37

Re: Question about proc sg plot and group = option

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;

Can also be found at

Thanks.

Harshad M.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 15 replies
  • 1018 views
  • 1 like
  • 7 in conversation