Professional Documents
Culture Documents
Problem
Given a list of pizza toppings, consider all the possible 3-topping pizzas, and print out the
total cost of those 3 toppings.
Input
Output
pizza costing
Cheese,Chicken,Pepperoni 1.45
Cheese,Chicken,Sausage 1.65
Cheese,Pepperoni,Sausage 1.6
Chicken,Pepperoni,Sausage 1.75
Dataset
data pizza_toppings;
attrib
Topping_name Label="Topping Name"
Ingredient_cost Label="Ingredient Cost";
infile datalines dsd dlm=',' truncover;
input Topping_name :$30. Ingredient_cost;
datalines;
"Pepperoni",0.50
"Sausage",0.70
"Chicken",0.55
"Cheese",0.40
;
Solution
proc sort data=pizza_toppings; by Topping_name; run;
proc sql noprint;
select distinct cat("'", strip(Topping_name), "'") as Topings,
count(distinct Topping_name) as Pizza_toppings
into :Topings separated by ' ', :n from Pizza_toppings;
quit;
data __temp;
set _temp;
pizza = catx(',',Pizza1 ,Pizza2, Pizza3 );
if ^missing(sum(of _numeric_));
array pizzas(*) $30. Pizza1-Pizza3;
costing = 0;
do i = 1 to dim(pizzas);
if ^missing(vvaluex(pizzas(i)));
costing + vvaluex(pizzas(i));
end;
Keep Pizza Costing;
proc print; run;
Output
-Vijay Pratap