/* create the sas table */
Data work.toppings;
topping='Mushrooms'; output;
topping='Onions'; output;
topping='Olives'; output;
topping='Zucchini';output;
topping='Pepperoni';output;
run;
/* sort the data */
proc sort data = toppings;
by topping;
run;
data _null_;
file _webout;
set work.toppings end=eof;
by topping;
if _N_ = 1 then
do; /* first row */
put " <html> ";
put " <head> ";
put " <!--Load the AJAX API--> ";
put ' <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> ';
put ' <script type="text/javascript"> ';
put " // Load the Visualization API and the corechart package. ";
put " google.charts.load('current', {'packages':['corechart']}); ";
put " // Set a callback to run when the Google Visualization API is loaded. ";
put " google.charts.setOnLoadCallback(drawChart); ";
put " // Callback that creates and populates a data table, ";
put " // instantiates the pie chart, passes in the data and ";
put " // draws it. ";
put " function drawChart() { ";
put " // Create the data table. ";
put " var data = new google.visualization.DataTable(); ";
put " data.addColumn('string', 'Topping'); ";
put " data.addColumn('number', 'Slices'); ";
put " data.addRows([ ";
put "['" topping "',1],"; /* output the first topping since it is first row. */
end; /* first row */
else
do; /* Not first row */
put "['" topping "',1],";
if eof then
do; /* eof */
put "['" topping "',2]";
put " ]); ";
put " // Set chart options ";
put " var options = {'title':'How Much Pizza I Ate Last Night', ";
put " 'width':400, ";
put " 'height':300}; ";
put " // Instantiate and draw our chart, passing in some options. ";
put " var chart = new google.visualization.PieChart(document.getElementById('chart_div')); ";
put " chart.draw(data, options); ";
put " } ";
put " </script> ";
put " </head> ";
put " <body> ";
put " <!--Div that will hold the pie chart--> ";
put ' <div id="chart_div"></div> ';
put " </body> ";
put " </html> ";
end; /* eof */
end; /* Not first row */
run;
... View more