10-18-2013 06:49 AM
I am really frustrated with this (In my opinion there should be an option for this in SAS). My intention is to graph a pie chart from the process. The process has three stages (on,off,sleep (not neccessary all of them)) and the shifting times vary case to case. I would need a pie chart from the cumulative time the process has been in each stage on each process.I have several(random) number of these processes and I have made a macro to loop through all the processes and graph the graphs for each process. However I would need the pie chart to always show the same color for the stage in the pie chart for each process. And that is where the problem occures.
Here is my code (inside a do loop i=1 to number of processes):
proc gchart data=print&i;
pie state2 /sumvar=duration descending value=none nogroupheading noheading nolegend;
%if %eval(&&count&i)=3 %then %do;
%if %eval(&&count&i)=2 %then %do;
%if %eval(&&count&i)=1 %then %do;
goptions reset=all colors=;
&&count&i tells how many stages the process has had (1-3)
and the &col1-&col3 gets values from the dataset(which has a variable telling the color) green yellow red depending on which stages appear on the process.
I have tested with %put that all the macro variables get the value wanted, so that is not the problem. Also the %if loops works as intented. However SAS doesn't take notice on the colors (Actually it does it randomly for example one chart can be in the right form but then the next gets 2 greens and one pink, or the colors are mixed so that yellow=green red=yellow green=red etc.)
The problem has to in the pattern statement itself or with the reset option idk. I hope this wasn't too confusing. Please help.
10-18-2013 09:07 AM
Hi, you have to read the doc on the PATTERN statement. Colors are not always assigned intuitively when you use a PATTERN statement. Robert's example from the Tech Support is a good example of how you have to "take control" if you want colors to stay consistent across groups.
10-21-2013 08:05 AM
Hi, and thanks for the answers. However the given code won't work as intended. My case is similar to what is in the example, in my case my grp is process ID and flavor is the state. I copy paste the code Robert posted here and replace all the variable references to fit my data. The results are even worse than with my code in the first post. The pies are either one colored or bicolored (never 3 colors). With R this would be a nobrainer, but unofortunately I have to get this to work on SAS too.
One change I had to remove, patternid=midpoints from the options since pie statement doesn't take that as an option.
10-21-2013 10:41 AM
The following code should get you what you want without all of the complexity (and no loops required :-)). The DISCRETEATTRMAP defines the association between values and the graph attributes (in this case, just color). A variable called ATTRSEX is defined in the DISCRETEATTRVAR statement to bind your real variable (sex) with the attrmap (gender). Then, just use that variable on the PIECHART statement. The attribute will be applied correctly regardless of data order, and data "drop outs" will no longer be a problem. If you have any questions, just let me know.
define statgraph pie;
value "F" / fillattrs=(color=pink);
value "M" / fillattrs=(color=blue);
discreteattrvar attrvar=attrsex var=sex attrmap="gender";
piechart category=attrsex response=height / name="mypie";
proc sgrender data=sashelp.class template=pie;
/* Put your BY statement here if you are doing a BY-group */
10-22-2013 02:01 AM
This sounds promising. However a ton of errors are created while running the code below
define statgraph pie;
value "On" / fillattrs=(color=green);
value "Off" / fillattrs=(color=red);
value "Standby" / fillattrs=(color=yellow);
discreteattrvar attrvar=attrstate var=state attrmap="state";
piechart category=attrstate response=duration / name="State distribution";
discretelegend "State distribution";
it seems that discreteattrmap is an invalid statement and piechart too... My sas version is 9.2 and I have had huge struggles with pie chart templates before (are they even possible to make?) however these are the errors I get:
19 discreteattrmap name="state";
20 value "On" / fillattrs=(color=green);
21 value "Off" / fillattrs=(color=red);
22 value "Standby" / fillattrs=(color=yellow);
24 discreteattrvar attrvar=attrstate var=state attrmap="state";
25 layout region;
26 piechart category=attrstate response=duration / name="State distribution";
ERROR 180-322: Statement is not valid or it is used out of proper order.
ERROR 22-322: Syntax error, expecting one of the following: DATALATTICE, DATAPANEL, GRIDDED, LATTICE,
OVERLAY, OVERLAY3D, OVERLAYEQUATED, PROTOTYPE.
ERROR 76-322: Syntax error, statement will be ignored.
WARNING 1-322: Assuming the symbol PIECHARTPARM was misspelled as piechart.