Data visualization with SAS programming

patterns across groups proc gchart

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 104
Accepted Solution

patterns across groups proc gchart

Hi SAS Users,


I would like to write a macro that will keep my same pattern (color and value) across each value. I have already started a macro, but I can't seem to get it to work.


For example, using the code below and I would always like the color blue assigned when class=1.  As some graph do not class=1 value, I do not want the color blue then assigned to class=2.  Using this current code, for a dataset with values class=2 and class=3, the color assigned is red for both class values whereas it should be class=2 is red and class=3 is green.


Thanks!


data _null_;

   set have end=last;

   length color $20 value $5;      

select;

      when (class=1) do;

         color="Blue"; value="solid";  

       end;

      when (class=2) do;

         color="Red"; value="solid";

      end;

      when (class=3) do;

         color="Green"; value="solid";

      end;

      otherwise;

   end;   

if last then call symput('last',_n_);

call symput('pattern'||trim(left(put(_n_,8.))),'color=' || color || ' value=' || value ||';');                                      

run;     

%macro pattern;

   %do j=1 %to &last;    

   %end;

%mend pattern;

%pattern;


Accepted Solutions
Solution
‎10-05-2012 03:31 PM
SAS Super FREQ
Posts: 864

Re: patterns across groups proc gchart

If you have SAS 9.3, this is a trivial problem. In SAS 9.3, you can define was is called an "attribute map" data set that you can use in the SG procedures (SGPLOT, SGPANEL, SGSCATTER). I wrote a couple of blog entries with examples of how you can use them. IN your case, you are creating bar charts, so you would use the FILLCOLOR column to set your colors and use SGPLOT or SGPANEL to create your bar charts. The nice thing is that you can reuse this dataset to accomplish what you wanted with your macro. Also, the dataset can contain MULTIPLE attribute maps that you can reference from the procedure by attrid.

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/

Hope this helps!

Dan

View solution in original post


All Replies
Solution
‎10-05-2012 03:31 PM
SAS Super FREQ
Posts: 864

Re: patterns across groups proc gchart

If you have SAS 9.3, this is a trivial problem. In SAS 9.3, you can define was is called an "attribute map" data set that you can use in the SG procedures (SGPLOT, SGPANEL, SGSCATTER). I wrote a couple of blog entries with examples of how you can use them. IN your case, you are creating bar charts, so you would use the FILLCOLOR column to set your colors and use SGPLOT or SGPANEL to create your bar charts. The nice thing is that you can reuse this dataset to accomplish what you wanted with your macro. Also, the dataset can contain MULTIPLE attribute maps that you can reference from the procedure by attrid.

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/

Hope this helps!

Dan

Valued Guide
Posts: 632

Re: patterns across groups proc gchart

If you can go with the newer SG procedures then follow Dan's suggestions, but take a look at this paper as well.

http://www.lexjansen.com/wuss/2012/142.pdf

However if as your question suggests, you are not using the the SG procedures, then take a look at this paper.

http://www2.sas.com/proceedings/sugi29/086-29.pdf

Although these two papers are directed at GPLOT and SGPLOT the concept with the legends, symbols, and patterns are similar.

If these do not clear up things for you come back and reframe your question.  There are also Macro issues in your code that may then need to be addressed.

Frequent Contributor
Posts: 104

Re: patterns across groups proc gchart

I did end up trying it both ways - once using just proc gchart and creating dummy variables and a code supplied by a paper provided by ArtC http://www2.sas.com/proceedings/sugi29/086-29.pdf.

I also then used the newer SG procedures and found Dan's suggestions and supplied papers helpful.  I guess I should start the transition to using the newer SG procedures.

Thank you both for your help.

Post a Question
Discussion Stats
  • 3 replies
  • 238 views
  • 3 likes
  • 3 in conversation