<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Pie of a Pie Chart in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Pie-of-a-Pie-Chart/m-p/458932#M15817</link>
    <description>&lt;P&gt;Good Evening Fellow SAS Boffins,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am in the process of&amp;nbsp;replacing a number of manually updated graphs in a Word document with SAS&lt;SPAN&gt;&amp;nbsp;(9.4m4)&amp;nbsp;&lt;/SPAN&gt;alternatives.&amp;nbsp; I have&amp;nbsp;hit a dead end when it comes to replicating a Pie of a Pie Chart similar to the image below.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not married to the concept of using SAS/GRAPH and ODS if there is an AMO or VA alternative I would be keen to explore the idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Pie of a Pie Chart.gif" style="width: 365px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20286iD67CCF2320738E98/image-size/large?v=v2&amp;amp;px=999" role="button" title="Pie of a Pie Chart.gif" alt="Pie of a Pie Chart.gif" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 01 May 2018 09:50:02 GMT</pubDate>
    <dc:creator>Scott_Mitchell</dc:creator>
    <dc:date>2018-05-01T09:50:02Z</dc:date>
    <item>
      <title>Pie of a Pie Chart</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Pie-of-a-Pie-Chart/m-p/458932#M15817</link>
      <description>&lt;P&gt;Good Evening Fellow SAS Boffins,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am in the process of&amp;nbsp;replacing a number of manually updated graphs in a Word document with SAS&lt;SPAN&gt;&amp;nbsp;(9.4m4)&amp;nbsp;&lt;/SPAN&gt;alternatives.&amp;nbsp; I have&amp;nbsp;hit a dead end when it comes to replicating a Pie of a Pie Chart similar to the image below.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not married to the concept of using SAS/GRAPH and ODS if there is an AMO or VA alternative I would be keen to explore the idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Pie of a Pie Chart.gif" style="width: 365px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20286iD67CCF2320738E98/image-size/large?v=v2&amp;amp;px=999" role="button" title="Pie of a Pie Chart.gif" alt="Pie of a Pie Chart.gif" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 May 2018 09:50:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Pie-of-a-Pie-Chart/m-p/458932#M15817</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2018-05-01T09:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: Pie of a Pie Chart</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Pie-of-a-Pie-Chart/m-p/458937#M15818</link>
      <description>&lt;P&gt;Well, I don't know myself, have a look through this blog, its my goto to find anything graph orientated, and has examples:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/graphicallyspeaking/" target="_blank"&gt;http://blogs.sas.com/content/graphicallyspeaking/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It may be that you need to create two graphs side by side, only the right one with a legend:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/graphicallyspeaking/2012/03/26/let-them-eat-pie/" target="_blank"&gt;https://blogs.sas.com/content/graphicallyspeaking/2012/03/26/let-them-eat-pie/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Something like that with two pie charts.&lt;/P&gt;</description>
      <pubDate>Tue, 01 May 2018 09:41:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Pie-of-a-Pie-Chart/m-p/458937#M15818</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-01T09:41:05Z</dc:date>
    </item>
    <item>
      <title>Re: Pie of a Pie Chart</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Pie-of-a-Pie-Chart/m-p/458941#M15821</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;.&amp;nbsp; I have spent a fair chunk of the day going through that blog (and others).&amp;nbsp; It is a great resource.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was also considering the concept of having 2 pie graphs side by side, but I doubt the stakeholders will buy into it.&amp;nbsp; They are pretty committed to the existing look and feel, but may have to make some concessions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you again.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 May 2018 10:00:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Pie-of-a-Pie-Chart/m-p/458941#M15821</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2018-05-01T10:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: Pie of a Pie Chart</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Pie-of-a-Pie-Chart/m-p/458950#M15822</link>
      <description>&lt;P&gt;&lt;A href="http://robslink.com/" target="_blank" rel="noopener"&gt;http://robslink.com/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;@&amp;nbsp;Robert Allison&amp;nbsp; might make it happen via SAS/GRAPH .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UPDATED:&lt;/P&gt;
&lt;P&gt;I know it is too old.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just want to post my code (PROC SGPLOT) for somebody who need it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value $fmt(default=80)
'Very Heavy (&amp;gt; 25)','Moderate (6-15)','Light (1-5)'=' other'; /*add a white blank before 'other' is to make 'other' appeared at first place in PERCENT_MAIN dataset*/
run;

data have;
 set sashelp.heart(keep=Smoking_Status rename=(Smoking_Status=type) where=(type is not missing));
 category=put(type,$fmt.);
run;
proc freq data=have noprint order=internal;
table category/out=percent_main;      /*get main pie percent*/
table category*Type/out=percent_all;  /*get sub pie percent*/
run;
/*process main pie*/
data main_temp;
set percent_main;
PERCENT=0.01*PERCENT;
if _n_=1 then percent_cum=PERCENT/2;  /*when category='other'*/
 else percent_cum+PERCENT;
keep category percent_cum PERCENT;
format PERCENT percent8.2;
run;
data main_pie;
 set main_temp;
 pi=constant('pi');
 lag_percent_cum=lag(percent_cum);

 id=_n_;x=0;y=0;output;
 if _n_=1 then do;  /*when category='other'*/
   do theta=-2*pi*percent_cum to 2*pi*percent_cum by 0.001;
     x=cos(theta);y=sin(theta); output;
   end;
 end;
 else do;
    do theta=2*pi*lag_percent_cum to 2*pi*percent_cum by 0.001;
     x=cos(theta);y=sin(theta); output;
   end;
 end;
 keep category id x y PERCENT;
run;
/*Keep line position*/
data line_pos(rename=(id=line_id x=line_x y=line_y));
 set main_pie(where=(id=1 and x ne 0)) end=last;
 if _n_=1 then do;output;x=2;y=-0.5;output;end;
 if last  then do;id=id+1;output;x=2;y=0.5;output;end;
 keep id x y;
run;


/*process sub pie*/
proc sql;
create table sub_temp as
select type,0.01*PERCENT as PERCENT format=percent8.2,PERCENT/sum(PERCENT) as new_percent
 from  percent_all
  where strip(category)='other';
quit;
data sub_temp;
set sub_temp(rename=(type=category));
percent_cum+new_percent;
keep category percent_cum PERCENT;
run;
data sub_pie;
 set sub_temp;
 pi=constant('pi');
 lag_percent_cum=coalesce(lag(percent_cum),0);

 id=10000+_n_;x=2;y=0;output;
 do theta=2*pi*lag_percent_cum to 2*pi*percent_cum by 0.001;
     x=2+0.5*cos(theta);y=0.5*sin(theta); output;
 end;
 keep category id x y PERCENT;
run;



/*Plot pie of pie chart*/
data pie;
 length category $ 200;
 set main_pie sub_pie line_pos;
run;
ods graphics/noborder ANTIALIAS ANTIALIASMAX=10000000 width=800px height=600px;
proc sgplot data=pie aspect=0.6;
series x=line_x y=line_y/group=line_id lineattrs=(color=black);
polygon id=id x=x y=y/group=category label=PERCENT labelattrs=(color=black size=12) fill nooutline dataskin=sheen
 LABELLOC=INSIDEBBOX  LABELPOS=CENTER name='x';
xaxis display=none;
yaxis display=none;
keylegend 'x'/location=inside position=se across=1 exclude=('other' ' ')  autoitemsize VALUEATTRS=(size=10);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1709626140211.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94389i87D90CFCFF6B9161/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1709626140211.png" alt="Ksharp_0-1709626140211.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2024 08:09:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Pie-of-a-Pie-Chart/m-p/458950#M15822</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-03-05T08:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: Pie of a Pie Chart</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Pie-of-a-Pie-Chart/m-p/459048#M15826</link>
      <description>&lt;P&gt;Hello, I found this topic while I was hanging out at PharmaSUG and thought it looked like a fun challenge. I made an example of doing this with the CARS dataset within the SASHELP library.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The program gets the frequencies (I get rid of hybrid due to it's very small size in the example).&amp;nbsp; I make the pie slices with the Polygon plot, the outlines with series plot, and the percentages with TEXT plot.&amp;nbsp; Note I have to do a great bit of trigonometry to make this work where I assume the left circle has a radius of 1.&amp;nbsp; If you need to change the size of this circle then some changes to code would need to happen.&amp;nbsp; I force any percentages smaller than 8% into a separate group, and then make the second pie chart based on them.&amp;nbsp; I have a macro variable in a %let to determine the distance between the circles.&amp;nbsp; It should autosize the second circle based on this macro variable.&amp;nbsp; There are many tweaks I could do to make it look better, but I think it's a fun start.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pieofpie.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20294i8275EECA0680C718/image-size/large?v=v2&amp;amp;px=999" role="button" title="pieofpie.png" alt="pieofpie.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=sashelp.cars noprint;
    table type / out=frq;
    where type ^='Hybrid';
run;

proc sql;
    create table plota as
        select type,sum(percent) as percent from
        (select ifc(percent lt 8,' ',type) as type,(percent lt 8) as other,percent from frq)
        group by type;
    create table plotb as   
        select type,percent,percent/sum(percent) as ppt,sum(percent) as othpct from frq where percent lt 8;
quit;

%let dist=2;
data plota2 (drop=text xtext ytext) texta (keep=text xtext ytext);
    set plota end=last;
    retain endpoint id;
    percent=percent/100;
    if type=' ' then do;
        id=1;
        text=strip(put(percent*100,12.0))||'%';
        xtext=0.5*cos(0);ytext=0.5*sin(0);output texta;
        series=1;x=0;y=0;output plota2;
        series=0;
        do i = (2*constant('pi'))*(-percent/2) to (2*constant('pi'))*(percent/2) by (2*constant('pi'))*(percent/50);
            x=1*cos(i);
            y=1*sin(i);
            output plota2;
        end;
        series=1;x=x*(&amp;amp;dist/cos(percent*constant('pi')));y=y*(&amp;amp;dist/cos(percent*constant('pi')));output plota2;
        endpoint=percent/2;
    end;
    else do;
        id=id+1;
        text=strip(put(percent*100,12.0))||'%';
        xtext=0.6*cos(2*constant('pi')*(percent/2+endpoint));ytext=0.6*sin(2*constant('pi')*(percent/2+endpoint));output texta;
        series=1;x=0;y=0;output plota2;  
        series=0;
        do i = (2*constant('pi'))*(endpoint) to (2*constant('pi'))*(percent+endpoint) by (2*constant('pi'))*(percent/50);
            x=1*cos(i);
            y=1*sin(i);
            output plota2;
        end;
        if last then do;
            series=1;x=x*(&amp;amp;dist/cos(percent*constant('pi')));y=y*(&amp;amp;dist/cos(percent*constant('pi')));output plota2;
        end;
        else do;
            series=1;output plota2;        
        end;
        endpoint=endpoint+percent;
    end;
run;

data plotb2(drop=text xtext ytext) textb (keep=text xtext ytext);
    set plotb;
    retain endpoint id;
    if _n_=1 then do;
        endpoint=0;
        call symput('radius',strip(put(2*&amp;amp;dist*tan(othpct/100*constant('pi')),best12.)));
    end;
    id+1;
    text=strip(put(percent,12.0))||'%';
    xtext=&amp;amp;dist+0.5*(&amp;amp;dist*tan(othpct/100*constant('pi')))*cos(2*constant('pi')*(ppt/2+endpoint));
    ytext=0.5*(&amp;amp;dist*tan(othpct/100*constant('pi')))*sin(2*constant('pi')*(ppt/2+endpoint));output textb;
    series=1;x=&amp;amp;dist;y=0;output plotb2;  
    series=0;
    do i = (2*constant('pi'))*(endpoint) to (2*constant('pi'))*(ppt+endpoint) by (2*constant('pi'))*(ppt/50);
        x=&amp;amp;dist+(&amp;amp;dist*tan(othpct/100*constant('pi')))*cos(i);
        y=(&amp;amp;dist*tan(othpct/100*constant('pi')))*sin(i);
        output plotb2;
    end;
    series=1;output plotb2;
    endpoint=endpoint+ppt;
run;

data text;
    set texta textb;
run;
data plot;
    set plota2 (in=a) plotb2 (in=b);
    retain lastid;
    if a then lastid=id;
    else if b then do;
        circle=2;
        id=id+lastid;
    end;
run;

data plot;
    merge plot text;
    run;
ods path WORK.TEMPLAT(UPDATE) SASHELP.TMPLMST (READ);
proc template;
    define statgraph pieofpie;
    begingraph / designheight=5in designwidth=10in;
    
    layout overlay / xaxisopts=(display=none linearopts=(viewmin=-1.1 viewmax=4)) yaxisopts=(display=none linearopts=(viewmin=-1.1 viewmax=1.1));
        /*Left Pie Chart*/
        polygonplot x=eval(ifn(circle^=2,x,.)) y=y id=id / outlineattrs=(color=black pattern=1) display=(fill) group=type name='p1';
        seriesplot x=eval(ifn(series=1 and circle^=2,x,.)) y=y / lineattrs=(color=black pattern=1) group=id;
        polygonplot x=eval(ifn(circle=2,x,.)) y=y id=id / outlineattrs=(color=black pattern=1) display=(fill) group=type name='p2';
        seriesplot x=eval(ifn(series=1 and circle=2,x,.)) y=y / lineattrs=(color=black pattern=1) group=id;
        DRAWOVAL X=0 Y=0 WIDTH=2 HEIGHT=2 / display=(outline) outlineattrs=(color=black) heightunit=data 
            drawspace=datavalue widthunit=data;
        DRAWOVAL X=&amp;amp;dist Y=0 WIDTH=%sysevalf(&amp;amp;radius) HEIGHT=%sysevalf(&amp;amp;radius) / display=(outline) outlineattrs=(color=black) heightunit=data 
            drawspace=datavalue widthunit=data;
            
        textplot x=xtext y=ytext text=text / textattrs=(size=16pt) position=center;
        discretelegend 'p1'  / exclude=(' ') location=inside halign=right valign=center border=false across=1 valueattrs=(size=18pt)
            displayclipped=true;
    endlayout;
    
    endgraph;
    end;
run;
ods graphics / reset scale=off imagename='pieofpie'; 
proc sgrender data=plot template=pieofpie;
run;

        &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 May 2018 18:11:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Pie-of-a-Pie-Chart/m-p/459048#M15826</guid>
      <dc:creator>JeffMeyers</dc:creator>
      <dc:date>2018-05-01T18:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: Pie of a Pie Chart</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Pie-of-a-Pie-Chart/m-p/459222#M15830</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/2153"&gt;@JeffMeyers&lt;/a&gt;&amp;nbsp;that is a truly outstanding solution.&amp;nbsp; I can't wait to try it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks also to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;for their valuable input.&lt;/P&gt;</description>
      <pubDate>Wed, 02 May 2018 10:10:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Pie-of-a-Pie-Chart/m-p/459222#M15830</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2018-05-02T10:10:05Z</dc:date>
    </item>
  </channel>
</rss>

