Data test2; input Stdnt_Count @3 Race $9.; cards; 20 Hispanic 45 White 30 Black 05 Asian ;;;; run; %macro PieChart( _dset, _Var, _Val_labels, _chtType_, _ChtSize_, _ChartTitle_); /*****************************************************************************/ /* Macro: PieChart.SAS Date: 11/11/2007 */ /* Auth: Phil Rack, MineQuest, llc Revd: */ /* */ /* Parms: */ /* %PieChart(Dataset, Variable, VarLabels, ChartType, ChartSize, ChartTitle) */ /* */ /* Where: */ /* Dataset - then name of the dataset containing the values to be plotted */ /* Variable - the variable that contains the numeric counts */ /* VarLabels - The variable that contains the labels for the pie slices */ /* ChartType - P2 for 2-dimensional chart. P3 for 3-dimensional chart */ /* ChartSize - SM=Small, MED=Medium, LG = Large */ /* ChartTitle - The title for the chart. Spaces should have a '+' sign */ /* */ /* Desc: Takes two variables from a data set and creates a Piechart calling */ /* the google chart api. */ /* */ /*****************************************************************************/ Proc Contents data= &_dset noprint out=_plotP3temp_; Run; *--> get the number of obs which will be the number of vars after the transpose; Data _null_; Set _plotP3temp_; if _n_=1; Call symput('Nobs',compress(nobs)); %let lastcol=col&nobs; Run; *--> flip the data so that we can get it in a form for further processing; Proc Transpose data= &_dset out=_transVal_ prefix=val; VAR &_Val_labels ; Run; Proc Transpose data= &_dset out= _TransCnt_ prefix=cnt; var &_var; Run; data _trans_; merge _transVal_ _TransCnt_; Run; *--> build the strings needed so we can pass them to google; Data _PlotData_(keep=value_label Count_label); Set _trans_; Length Value_label count_label $ 2048; value_label = ''; Count_label = ''; Array Cntcol{&nobs} Cnt1--Cnt&&nobs; Array valcol{&nobs} Val1--Val&&nobs; *--> the pie slice labels; Do ii=1 to &nobs; if (ii ge 1) and (ii lt &nobs) then do; value_label = compress(ValCol{ii}||'-'||'('||CntCol{ii}||')'||'|'||Value_label ); Count_label = compress(cntCol{ii}||','||Count_label); End; if (ii = &nobs) then do; value_label = compress(Value_label||ValCol{ii}||'-'||'('||CntCol{ii}||')' ); Count_label = compress(count_label||cntCol{ii}); End; End; Run; *--> create the macro variables that will contain the values to be passed to google; Data initmacrovars; Set _plotdata_; Call symput('Value_label',compress(value_label)); Call symput('Count_Vals', compress(Count_label)); Run; *--> delete the temporary data sets - no longer needed; Proc datasets ddname=work; delete initmacrovars _labels_ _plotdata_ _counts_; quit; Run; *--> pass the url to internet explorer and invoke the google graphics service; Data _null_; length cmdf $ 2048; %let chartSize=; %let _ChartType_=; *--> get the size of the charts in pixels; %if %upcase("&&_chtSize_") = "SM" %then %let ChartSize = 350x150; %else %if %upcase("&&_chtSize_") = "MED" %then %let ChartSize = 450x200; %else %if %Upcase("&&_chtSize_") = "LG" %then %let ChartSize = 800x350; %else %let ChartSize = 450x200; *--> use this as the default if sm, med or lg not chosen; %if %upcase("&_chtType_") = "3D" %then %let _ChartType_ = p3; %else %if %upcase("&_chtType_") = "2D" %then %let _ChartType_ = p; %else %let _ChartType_ = p; *--> Build the command string to call the google web service; gURL = "&&webbrowser http://chart.apis.google.com/chart?chf=bg,s,efefef&cht=&&_ChartType_&chd=t:&&count_vals"|| "&chtt=&&_ChartTitle_&chs=&&chartsize&chl=&&value_label"; Put 'This is the URL that is being passed to internet explorer.'; put gURL; Call System(gURL); Run; %Mend PieChart; options noxsync; *--> create 3 Piecharts of varying sizes; %PieChart(Test2, Stdnt_count, Race, 3D, SM,Student+Racial+Composition); %PieChart(Test2, Stdnt_count, Race, 3D, Med,Student+Racial+Composition); %PieChart(Test2, Stdnt_count, Race, 2D, LG,Student+Racial+Composition);