216.ANALYZING VARIETIES OF BISCUITS WORLDWIDE USING PROC SQL AND MACROS IN SAS WITH GLOBAL PRICE RATINGS FLAVOR BASED INSIGHTS AND COUNTRY WISE BRAND COMPARISON
ANALYZING VARIETIES OF BISCUITS WORLDWIDE USING PROC SQL AND MACROS IN SAS WITH GLOBAL PRICE RATINGS FLAVOR BASED INSIGHTS AND COUNTRY WISE BRAND COMPARISON
/*Creating a unique dataset on Varieties of Biscuits Worldwide*/
/* STEP 1: Creating a Biscuit Dataset Using PROC SQL */
proc sql;
create table Biscuits_Worldwide (
Biscuit_ID num,
Brand char(20),
Country char(15),
Flavor char(15),
Description char(30),
Price_Per_Kg num,
Rating num
);
insert into Biscuits_Worldwide values(1, "Oreo", "USA", "Sweet", "Chocolate Cream", 10.5, 4.5);
insert into Biscuits_Worldwide values(2, "Parle-G", "India", "Sweet", "Classic Glucose", 2.0, 4.2);
insert into Biscuits_Worldwide values(3, "Digestive", "UK", "Semi-Sweet", "Wheat Biscuit", 6.0, 4.1);
insert into Biscuits_Worldwide values(4, "Tim Tam", "Australia", "Sweet", "Choco Layered", 12.0, 4.6);
insert into Biscuits_Worldwide values(5, "Marie Gold", "India", "Light-Sweet", "Tea Biscuit", 3.5, 4.0);
insert into Biscuits_Worldwide values(6, "Bourbon", "India", "Sweet", "Chocolate Sandwich", 5.5, 4.3);
insert into Biscuits_Worldwide values(7, "Good Day", "India", "Butter", "Cashew and Butter", 4.2, 4.1);
insert into Biscuits_Worldwide values(8, "Nice", "India", "Coconut", "Coconut Sugar Biscuit", 4.0, 3.9);
insert into Biscuits_Worldwide values(9, "TUC", "Belgium", "Salty", "Salted Crackers", 7.0, 4.0);
insert into Biscuits_Worldwide values(10, "Ritz", "USA", "Salty", "Buttery Crackers", 8.0, 4.2);
insert into Biscuits_Worldwide values(11, "Leibniz", "Germany", "Sweet", "Butter Biscuit", 9.0, 4.4);
insert into Biscuits_Worldwide values(12, "Pally", "Netherlands", "Savory", "Cheese Herb", 6.5, 4.0);
insert into Biscuits_Worldwide values(13, "Chips Ahoy", "USA", "Sweet", "Choco Chip Cookie", 11.0, 4.3);
insert into Biscuits_Worldwide values(14, "Mcvities Hobnobs", "UK", "Oaty", "Oat Cookies", 7.5, 4.2);
insert into Biscuits_Worldwide values(15, "Prince", "France", "Sweet", "Choco Filled", 9.5, 4.5);
insert into Biscuits_Worldwide values(16, "Lotus Biscoff", "Belgium", "Caramel", "Spiced Caramelized", 10.0, 4.7);
insert into Biscuits_Worldwide values(17, "Mcvities Jaffa", "UK", "Sweet", "Orange & Choco", 8.5, 4.1);
insert into Biscuits_Worldwide values(18, "Cracker Jack", "USA", "Salty", "Savory Snack Biscuits", 6.0, 3.8);
quit;
proc print;run;
Output:
| Obs | Biscuit_ID | Brand | Country | Flavor | Description | Price_Per_Kg | Rating |
|---|---|---|---|---|---|---|---|
| 1 | 1 | Oreo | USA | Sweet | Chocolate Cream | 10.5 | 4.5 |
| 2 | 2 | Parle-G | India | Sweet | Classic Glucose | 2.0 | 4.2 |
| 3 | 3 | Digestive | UK | Semi-Sweet | Wheat Biscuit | 6.0 | 4.1 |
| 4 | 4 | Tim Tam | Australia | Sweet | Choco Layered | 12.0 | 4.6 |
| 5 | 5 | Marie Gold | India | Light-Sweet | Tea Biscuit | 3.5 | 4.0 |
| 6 | 6 | Bourbon | India | Sweet | Chocolate Sandwich | 5.5 | 4.3 |
| 7 | 7 | Good Day | India | Butter | Cashew and Butter | 4.2 | 4.1 |
| 8 | 8 | Nice | India | Coconut | Coconut Sugar Biscuit | 4.0 | 3.9 |
| 9 | 9 | TUC | Belgium | Salty | Salted Crackers | 7.0 | 4.0 |
| 10 | 10 | Ritz | USA | Salty | Buttery Crackers | 8.0 | 4.2 |
| 11 | 11 | Leibniz | Germany | Sweet | Butter Biscuit | 9.0 | 4.4 |
| 12 | 12 | Pally | Netherlands | Savory | Cheese Herb | 6.5 | 4.0 |
| 13 | 13 | Chips Ahoy | USA | Sweet | Choco Chip Cookie | 11.0 | 4.3 |
| 14 | 14 | Mcvities Hobnobs | UK | Oaty | Oat Cookies | 7.5 | 4.2 |
| 15 | 15 | Prince | France | Sweet | Choco Filled | 9.5 | 4.5 |
| 16 | 16 | Lotus Biscoff | Belgium | Caramel | Spiced Caramelized | 10.0 | 4.7 |
| 17 | 17 | Mcvities Jaffa | UK | Sweet | Orange & Choco | 8.5 | 4.1 |
| 18 | 18 | Cracker Jack | USA | Salty | Savory Snack Biscuits | 6.0 | 3.8 |
/* STEP 2: View All Records */
proc sql;
title "All Varieties of Biscuits Worldwide";
select * from Biscuits_Worldwide;
quit;
Output:
| All Varieties of Biscuits Worldwide |
| Biscuit_ID | Brand | Country | Flavor | Description | Price_Per_Kg | Rating |
|---|---|---|---|---|---|---|
| 1 | Oreo | USA | Sweet | Chocolate Cream | 10.5 | 4.5 |
| 2 | Parle-G | India | Sweet | Classic Glucose | 2 | 4.2 |
| 3 | Digestive | UK | Semi-Sweet | Wheat Biscuit | 6 | 4.1 |
| 4 | Tim Tam | Australia | Sweet | Choco Layered | 12 | 4.6 |
| 5 | Marie Gold | India | Light-Sweet | Tea Biscuit | 3.5 | 4 |
| 6 | Bourbon | India | Sweet | Chocolate Sandwich | 5.5 | 4.3 |
| 7 | Good Day | India | Butter | Cashew and Butter | 4.2 | 4.1 |
| 8 | Nice | India | Coconut | Coconut Sugar Biscuit | 4 | 3.9 |
| 9 | TUC | Belgium | Salty | Salted Crackers | 7 | 4 |
| 10 | Ritz | USA | Salty | Buttery Crackers | 8 | 4.2 |
| 11 | Leibniz | Germany | Sweet | Butter Biscuit | 9 | 4.4 |
| 12 | Pally | Netherlands | Savory | Cheese Herb | 6.5 | 4 |
| 13 | Chips Ahoy | USA | Sweet | Choco Chip Cookie | 11 | 4.3 |
| 14 | Mcvities Hobnobs | UK | Oaty | Oat Cookies | 7.5 | 4.2 |
| 15 | Prince | France | Sweet | Choco Filled | 9.5 | 4.5 |
| 16 | Lotus Biscoff | Belgium | Caramel | Spiced Caramelized | 10 | 4.7 |
| 17 | Mcvities Jaffa | UK | Sweet | Orange & Choco | 8.5 | 4.1 |
| 18 | Cracker Jack | USA | Salty | Savory Snack Biscuits | 6 | 3.8 |
/* STEP 3: Summary by Country */
proc sql;
title "Average Price and Rating of Biscuits by Country";
select Country, count(*) as Total_Brands,
mean(Price_Per_Kg) as Avg_Price format=8.2,
mean(Rating) as Avg_Rating format=3.2
from Biscuits_Worldwide
group by Country
order by Avg_Rating desc;
quit;
Output:
| Average Price and Rating of Biscuits by Country |
| Country | Total_Brands | Avg_Price | Avg_Rating |
|---|---|---|---|
| Australia | 1 | 12.00 | 4.6 |
| France | 1 | 9.50 | 4.5 |
| Germany | 1 | 9.00 | 4.4 |
| Belgium | 2 | 8.50 | 4.4 |
| USA | 4 | 8.88 | 4.2 |
| UK | 3 | 7.33 | 4.1 |
| India | 5 | 3.84 | 4.1 |
| Netherlands | 1 | 6.50 | 4.0 |
/* STEP 4: Top 5 Expensive Biscuits */
proc sql outobs=5;
title "Top 5 Most Expensive Biscuits in the World";
select Brand, Country, Price_Per_Kg, Rating
from Biscuits_Worldwide
order by Price_Per_Kg desc;
quit;
Output:
| Top 5 Most Expensive Biscuits in the World |
| Brand | Country | Price_Per_Kg | Rating |
|---|---|---|---|
| Tim Tam | Australia | 12 | 4.6 |
| Chips Ahoy | USA | 11 | 4.3 |
| Oreo | USA | 10.5 | 4.5 |
| Lotus Biscoff | Belgium | 10 | 4.7 |
| Prince | France | 9.5 | 4.5 |
/* STEP 5: Top Rated Biscuits per Flavor */
proc sql;
title "Top Rated Biscuits per Flavor Type";
select Flavor, Brand, Country, max(Rating) as Top_Rating
from Biscuits_Worldwide
group by Flavor;
quit;
Output:
| Top Rated Biscuits per Flavor Type |
| Flavor | Brand | Country | Top_Rating |
|---|---|---|---|
| Butter | Good Day | India | 4.1 |
| Caramel | Lotus Biscoff | Belgium | 4.7 |
| Coconut | Nice | India | 3.9 |
| Light-Sweet | Marie Gold | India | 4 |
| Oaty | Mcvities Hobnobs | UK | 4.2 |
| Salty | Ritz | USA | 4.2 |
| Salty | Cracker Jack | USA | 4.2 |
| Salty | TUC | Belgium | 4.2 |
| Savory | Pally | Netherlands | 4 |
| Semi-Sweet | Digestive | UK | 4.1 |
| Sweet | Prince | France | 4.6 |
| Sweet | Bourbon | India | 4.6 |
| Sweet | Chips Ahoy | USA | 4.6 |
| Sweet | Leibniz | Germany | 4.6 |
| Sweet | Oreo | USA | 4.6 |
| Sweet | Parle-G | India | 4.6 |
| Sweet | Tim Tam | Australia | 4.6 |
| Sweet | Mcvities Jaffa | UK | 4.6 |
/* STEP 6: Create Macro to Filter by Country */
%macro filter_country(cname);
proc sql;
title "Biscuit Varieties from &cname";
select Brand, Flavor, Description, Price_Per_Kg, Rating
from Biscuits_Worldwide
where Country = "&cname"
order by Rating desc;
quit;
%mend;
%filter_country(India);
Output:
| Biscuit Varieties from India |
| Brand | Flavor | Description | Price_Per_Kg | Rating |
|---|---|---|---|---|
| Bourbon | Sweet | Chocolate Sandwich | 5.5 | 4.3 |
| Parle-G | Sweet | Classic Glucose | 2 | 4.2 |
| Good Day | Butter | Cashew and Butter | 4.2 | 4.1 |
| Marie Gold | Light-Sweet | Tea Biscuit | 3.5 | 4 |
| Nice | Coconut | Coconut Sugar Biscuit | 4 | 3.9 |
%filter_country(USA);
Output:
| Biscuit Varieties from USA |
| Brand | Flavor | Description | Price_Per_Kg | Rating |
|---|---|---|---|---|
| Oreo | Sweet | Chocolate Cream | 10.5 | 4.5 |
| Chips Ahoy | Sweet | Choco Chip Cookie | 11 | 4.3 |
| Ritz | Salty | Buttery Crackers | 8 | 4.2 |
| Cracker Jack | Salty | Savory Snack Biscuits | 6 | 3.8 |
/* STEP 7: Macro to Analyze by Flavor */
%macro flavor_analysis(flv);
proc sql;
title "Biscuit Analysis for &flv Flavor";
select count(*) as Count,
avg(Price_Per_Kg) as Avg_Price format=8.2,
avg(Rating) as Avg_Rating format=3.2
from Biscuits_Worldwide
where Flavor = "&flv";
quit;
%mend;
%flavor_analysis(Sweet);
Output:
| Biscuit Analysis for Sweet Flavor |
| Count | Avg_Price | Avg_Rating |
|---|---|---|
| 8 | 8.50 | 4.4 |
%flavor_analysis(Salty);
Output:
| Biscuit Analysis for Salty Flavor |
| Count | Avg_Price | Avg_Rating |
|---|---|---|
| 3 | 7.00 | 4.0 |
%flavor_analysis(Butter);
Output:
| Biscuit Analysis for Butter Flavor |
| Count | Avg_Price | Avg_Rating |
|---|---|---|
| 1 | 4.20 | 4.1 |
/* STEP 8: Identify Biscuits with Rating > 4.5 */
proc sql;
title "Highly Rated Biscuits (Rating > 4.5)";
select Brand, Country, Flavor, Rating
from Biscuits_Worldwide
where Rating > 4.5;
quit;
Output:
| Highly Rated Biscuits (Rating > 4.5) |
| Brand | Country | Flavor | Rating |
|---|---|---|---|
| Tim Tam | Australia | Sweet | 4.6 |
| Lotus Biscoff | Belgium | Caramel | 4.7 |
/* STEP 9: Country-wise Flavor Distribution */
proc sql;
title "Number of Biscuit Flavors per Country";
select Country, Flavor, count(*) as Count
from Biscuits_Worldwide
group by Country, Flavor
order by Country, Count desc;
quit;
Output:
| Number of Biscuit Flavors per Country |
| Country | Flavor | Count |
|---|---|---|
| Australia | Sweet | 1 |
| Belgium | Salty | 1 |
| Belgium | Caramel | 1 |
| France | Sweet | 1 |
| Germany | Sweet | 1 |
| India | Sweet | 2 |
| India | Coconut | 1 |
| India | Butter | 1 |
| India | Light-Sweet | 1 |
| Netherlands | Savory | 1 |
| UK | Sweet | 1 |
| UK | Semi-Sweet | 1 |
| UK | Oaty | 1 |
| USA | Sweet | 2 |
| USA | Salty | 2 |
/* STEP 10: Macro to Rank Biscuits in Each Country by Price */
%macro rank_biscuits_by_price;
proc sql;
title "Top Biscuit Brands by Price in Each Country";
create table Top_Priced_Biscuits as
select a.Country, a.Brand, a.Price_Per_Kg
from Biscuits_Worldwide as a
inner join (
select Country, max(Price_Per_Kg) as Max_Price
from Biscuits_Worldwide
group by Country
) as b
on a.Country = b.Country and a.Price_Per_Kg = b.Max_Price;
select * from Top_Priced_Biscuits;
quit;
%mend;
%rank_biscuits_by_price;
| Top Biscuit Brands by Price in Each Country |
| Country | Brand | Price_Per_Kg |
|---|---|---|
| Australia | Tim Tam | 12 |
| India | Bourbon | 5.5 |
| Germany | Leibniz | 9 |
| Netherlands | Pally | 6.5 |
| USA | Chips Ahoy | 11 |
| France | Prince | 9.5 |
| Belgium | Lotus Biscoff | 10 |
| UK | Mcvities Jaffa | 8.5 |
Comments
Post a Comment