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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

15 REPLIES 15
GraphGuy
Meteorite | Level 14

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

asishgautam
Calcite | Level 5

proc sgplot v 9.2

PGStats
Opal | Level 21

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

PG

PG
asishgautam
Calcite | Level 5

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

PGStats
Opal | Level 21

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
asishgautam
Calcite | Level 5

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.

stacey11
Calcite | Level 5

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?

DanH_sas
SAS Super FREQ

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

stacey11
Calcite | Level 5

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?

DanH_sas
SAS Super FREQ

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/

stacey11
Calcite | Level 5

Yes!  This worked great.  Thanks a lot!

HarshadMadhamshettiwar
Obsidian | Level 7

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.

DanH_sas
SAS Super FREQ

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;

HarshadMadhamshettiwar
Obsidian | Level 7

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 15 replies
  • 2582 views
  • 1 like
  • 7 in conversation