/*----------------------------------------------------------------------------------------*/ /* Macro for GTL Pie Chart */ /* Author: Sanjay Matange, SAS */ /* Date: June 25, 2018 */ /* History: 8/22/2012/SNM - Initial */ /* : 6/25/2018/SNM - Add 9.4 features */ /* */ /*----------------------------------------------------------------------------------------*/ %macro SGPIE ( Data=, /*--Data Set Name (Required)--*/ Category=, /*--Category Variable - Required--*/ Response=, /*--Response Variable - Optional--*/ Group=, /*--Group Variable - Optional--*/ URL=, /*--URL Variable - Optional--*/ CategoryLabel=True, /*--Include category value in slice label--*/ ResponseLabel=True, /*--Include response value in slice label--*/ PercentLabel=False, /*--Include percent value in slice label--*/ Legend=False, /*--Display Legend--*/ StartAngle=90, /*--Angle in degrees from East--*/ DataLabelLocation=Auto, /*--Data label location for slices--*/ Direction=CounterClockWise, /*--Pie Slices drawing direction--*/ DataSkin=Sheen, /*--Default data skin--*/ GroupGap=0, /*--Gap between group rings--*/ OtherSlice=True, /*--Group small values in one slice labeled "Other"--*/ GroupLabelFontSize=7, /*--Footnote Font Size--*/ DataLabelFontSize=8, /*--Footnote Font Size--*/ FootnoteFontSize=10, /*--Footnote Font Size--*/ TitleFontSize=12, /*--Title Font Size--*/ SubtitleFontSize=10, /*--Subtitle Font Size--*/ Footnote=, /*--Graph Footnote--*/ Footnote2=, /*--Graph Footnote--*/ Footnote3=, /*--Graph Footnote--*/ Title=, /*--Graph title2--*/ SubTitle=, /*--Graph Title--*/ Format=, /*--Format String--*/ LegendHalign=, /*--Horizontal position of legend--*/ LegendValign=, /*--Vertical position of legend--*/ LegendAcross=, /*--Number of columns--*/ LegendBorder=False, /*--Number of columns--*/ DataLabelContent=, /*--Format String--*/ DataColors=, /*--Format String--*/ DrillTarget=_blank, /*--Drill down tartet--*/ CenterFirstSlice=True /*--Center the first slice on the start angle--*/ ); %local NumCat Cat Resp Pct ResVar GroupVar; /*--Data set is required--*/ %if %length(&Data) eq 0 %then %do; %put The parameter 'Data' is required - GTLPieChart Macro Terminated.; %goto finished; %end; /*--Category is required--*/ %if %length(&Category) eq 0 %then %do; %put The parameter 'Category' is required - GTLPieChart Macro Terminated.; %goto finished; %end; /*--Response is optional--*/ %if %length(&Response) eq 0 %then %do; %let resvar=__not_assigned__; %end; %else %let resvar=&Response; /*--Group is optional--*/ %if %length(&Group) eq 0 %then %do; %let groupvar=__not_assigned__; %end; %else %let groupvar=&Group; /*--Generate the DataLabelContent option--*/ %let Content=DataLabelContent=none; %if %length(&CategoryLabel) ne 0 and %upcase(&CategoryLabel) eq TRUE %then %let cat=category; %else %let cat=; %if %length(&ResponseLabel) ne 0 and %upcase(&ResponseLabel) eq TRUE %then %let resp=response; %else %let resp=; %if %length(&PercentLabel) ne 0 and %upcase(&PercentLabel) eq TRUE %then %let pct=percent; %else %let pct=; %if %length(&cat) or %length(&resp) or %length(&pct) %then %do; %let content=DataLabelContent=(&cat &resp &pct); %end; /*-Add code to align a 2-slice pie vertically--*/ /*--Define template--*/ proc template; define statgraph GTLPieChart; begingraph %if %length(&dataColors) %then %do; / datacolors=(&dataColors) %end; ; entrytitle "&title" / textattrs=(size=&TitleFontSize); entryTitle halign=left "&subtitle" / textattrs=(size=&SubtitleFontSize); entryfootnote halign=left "&footnote" / textattrs=(size=&FootnoteFontSize); entryfootnote halign=left "&footnote2" / textattrs=(size=&FootnoteFontSize); entryfootnote halign=left "&footnote3" / textattrs=(size=&FootnoteFontSize); /*--Draw individual scatter plots in first row if needed--*/ layout region; piechart category=&category response=&resvar / outlineattrs=(pattern=solid) group=&groupvar name='a' dataskin=&dataskin start=&startangle groupgap=&groupgap datalabelattrs=(size=&datalabelfontsize) &content otherslice=&otherslice centerfirstslice=¢erfirstslice %if %length(&DataLabelContent) ne 0 %then %do; dataLabelContent=(&dataLabelContent) %end; %if %length(&URL) ne 0 %then %do; url=&url %end; ; %if %length(&Legend) ne 0 and %upcase(&Legend) eq TRUE %then %do; discretelegend 'a' / itemsize=(fillAspectRatio=golden) border=&legendBorder %if %length(&legendHalign) ne 0 %then %do; halign=&legendHalign %end; %if %length(&legendValign) ne 0 %then %do; valign=&legendValign %end; %if %length(&legendAcross) ne 0 %then %do; across=&legendAcross %end; ; %end; endlayout; endgraph; end; run; /*--Render the graph--*/ ods graphics / antialias=on subpixel=on %if %length(&URL) ne 0 %then %do; imagemap drilltarget="&drilltarget" %end; ; proc sgrender data=&data template=GTLPieChart; %if %length(&Format) ne 0 %then %do; &format; %end; run; %finished: %mend SGPIE; /*------------------End of Macro Definition-------------------------*/