%let name=elecgage; filename odsout '.'; %let htitle=6.5; %let htext=4.5; /* A sample at Sanjeev Kulkarni's request */ %let startangle=180; /* start/left side */ %let sweepangle=180; /* total angle of chart */ %let background=180; /* total angle of background pies */ %let grayoutline=graycc; /* pie slice outline */ %macro do_gage(mydata, titletext); %local mydata titletext; /* Prepare some calculated values to use later. */ data &mydata; set &mydata; line=_n_; end+slice; start=end-slice; swing=slice-slice2001; run; proc sql noprint; select min(start) into :min_start from &mydata; select max(end) into :max_end from &mydata; select sum(slice) into :sum_slice from &mydata; quit; run; data anno_title; length function color $8 style $35; xsys='3'; ysys='3'; hsys='3'; function='move'; x=0; y=85; output; function='bar'; color="graydd"; style="solid"; x=85; y=96; output; function='move'; x=85; y=85; output; function='bar'; color="cxdd0000"; style="solid"; x=100; y=96; output; function='label'; position='3'; size=&htitle; style='albany amt/bold'; x=2; y=85; text="&titletext"; color="black"; output; function='label'; position='3'; size=&htitle; style='albany amt/bold'; x=87; y=85; text=trim(left("&sum_slice")); color="white"; output; run; data anno_table; set &mydata; length function color $8 style $35 text $20; xsys='3'; ysys='3'; hsys='3'; function='label'; y=30-line*7; size=&htext; x=4; position='3'; style='marker'; color=slicecolor; text='U'; output; x=4; position='3'; style='markere'; color="&grayoutline"; text='U'; output; x=12; position='3'; style='albany amt/bold'; color="gray"; text=trim(left(party)); output; x=55; position='1'; style='albany amt'; color="black"; text=trim(left(slice2001)); output; x=70; position='1'; style='albany amt'; color="black"; text=trim(left(slice)); output; x=90; position='1'; style='albany amt'; color="gray"; text=trim(left(swing)); output; run; data anno_headers; length function color $8 style $35 text $20; xsys='3'; ysys='3'; hsys='3'; function='label'; y=30; size=&htext; x=12; position='3'; style='albany amt/bold'; color="gray"; text="Party"; output; x=55; position='1'; style='albany amt/bold'; color="gray"; text="2001"; output; x=70; position='1'; style='albany amt/bold'; color="gray"; text="2006"; output; x=90; position='1'; style='albany amt/bold'; color="gray"; text="Swing"; output; x=10; y=31; function='move'; output; x=93; function='draw'; size=.1; output; run; data anno_table; set anno_table anno_headers; run; data ranges arrow text; set &mydata; length html $500 text $100 function color $8 style $35; xsys='3'; ysys='3'; hsys='3'; when='A'; /* Draw color range segments */ x=50; y=45; size=32; function='PIE'; style='PSOLID'; line=3; min_start=&min_start; max_end=&max_end; percent_start=((start-&min_start)/(&max_end-&min_start)); percent_end=((end-&min_start)/(&max_end-&min_start)); angle_start=&startangle-((start-&min_start)/(&max_end-&min_start))*&sweepangle; angle_end=&startangle-((end-&min_start)/(&max_end-&min_start))*&sweepangle; angle=angle_end; rotate= (&startangle-((start-&min_start)/(&max_end-&min_start))*&sweepangle) - (&startangle-((end-&min_start)/(&max_end-&min_start))*&sweepangle) ; color=slicecolor; output ranges; /* Charttip for the pie slices and labels */ length html $200; html= 'title='||quote(trim(left(party))||': '||trim(left(slice)))|| ' href="elecgage_info.htm"'; style='PEMPTY'; color="&grayoutline"; output ranges; function='piexy'; size=.75; output; function='cntl2txt'; output; function='label'; color='black'; when='a'; text=trim(left(slice)); angle=0; rotate=0; style='albany amt/bold'; size=4.25; x=.; y=.; position='1'; if (slice/&sum_slice) < .05 then position='e'; if slicecolor eq 'black' and (slice/&sum_slice) >= .05 then color="white"; output ranges; run; data hub; length function color $8 style $35; xsys='3'; ysys='3'; hsys='3'; when='A'; x=50; y=45; length html $200; html= 'title='||quote(trim(left("&arrow_val")))|| ' href="elecgage_info.htm"'; /* need new charttip on slices, not on hub */ function='PIE'; style='PSOLID'; angle=0; rotate=&background; color="white"; size=12; output; color="&grayoutline"; size=12; style="pempty"; line=0; output; run; data gageanno; set ranges hub text anno_title anno_table; run; proc ganno annotate=gageanno des="" name="&name"; run; %mend do_gage; ODS LISTING CLOSE; ODS HTML path=odsout body="&name..htm" (title="Election Gage Chart (Custom SAS/Graph chart)") style=minimal options(pagebreak='no'); goptions border; goptions device=png; goptions hsize=4in vsize=4in; options mprint; /* %macro do_gage(mydata, titletext); */ data my_data; length slicecolor $8; input party $ 1-10 slicecolor slice slice2001; datalines; Left+ pink 235 199 Trinamul+ cxfdd017 30 59 Cong+ cyan 24 26 Others black 4 9 ; run; %do_gage(my_data,WEST BENGAL); data my_data; length slicecolor $8; input party $ 1-10 slicecolor slice slice2001; datalines; DMK+ pink 163 31 AIADMK+ cxfdd017 69 194 Others black 2 9 ; run; %do_gage(my_data,TAMIL NADU); data my_data; length slicecolor $8; input party $ 1-10 slicecolor slice slice2001; datalines; LDF pink 98 40 UDF cxfdd017 42 100 ; run; %do_gage(my_data,KERALA); data my_data; length slicecolor $8; input party $ 1-10 slicecolor slice slice2001; datalines; Cong+ pink 53 71 AGP+ cxfdd017 28 23 BJP cxf87a17 10 8 Others black 35 24 ; run; %do_gage(my_data,ASSAM); data my_data; length slicecolor $8; input party $ 1-10 slicecolor slice slice2001; datalines; Cong+ pink 20 13 AIADMK+ cxfdd017 7 3 Others black 3 14 ; run; %do_gage(my_data,PONDICHERRY); quit; ODS HTML CLOSE; ODS LISTING;