283.How Can SAS Analyze Different Types of Biryani Across the World Using PROC SQL, PROC FREQ, and PROC REPORT?

How Can SAS Analyze Different Types of Biryani Across the World Using PROC SQL, PROC FREQ, and PROC REPORT?

/*Creating a dataset of biryani types*/

 1) Create formats for readable outputs

PURPOSE: Define user-friendly labels for categorical variables

proc format;

  value $meatfmt

    'Mutton' = 'Mutton'

    'Chicken' = 'Chicken'

    'Beef' = 'Beef'

    'Fish' = 'Fish'

    'Vegetarian' = 'Vegetarian';

  value slevel

    1 = 'Mild'

    2 = 'Medium'

    3 = 'Hot'

    4 = 'Very Hot';

run;

Log:

NOTE: Format $MEATFMT has been output.
NOTE: Format SLEVEL has been output.

2) Creating the dataset with 7 variables and 12 observations

PURPOSE: Simulate a small but realistic global biryani dataset

options nocenter;

data biryani_master;

  infile datalines dsd truncover;

  length Biryani_ID 8 Biryani_Name $40 Country $30 Meat_Type $12 Rice_Type $20;

  input Biryani_ID Biryani_Name :$40. Country :$30. Meat_Type :$12. Spice_Level 

        Rice_Type :$20. Price_INR;

  format Spice_Level slevel.;

datalines;

1,Hyderabadi Dum Biryani,India,Mutton,3,Basmati,420

2,Kacchi Biryani,Bangladesh,Mutton,3,Basmati,380

3,Ambur Biryani,India,Chicken,2,Short-Grain,220

4,Beary Biryani,India,Beef,3,Parboiled,250

5,Thalassery Biryani,India,Chicken,2,Jeerakasala,300

6,Lucknowi (Awadhi) Biryani,India,Mutton,2,Basmati,450

7,Tehari Vegetarian Biryani,Pakistan,Vegetarian,1,Long-Grain,150

8,Thai-style Seafood Biryani,Thailand,Fish,2,Long-Grain,320

9,Calcutta Biryani,India,Chicken,2,Basmati,200

10,Sindhi Biryani,Pakistan,Beef,4,Basmati,360

11,Malabar Biryani,India,Chicken,3,Jeerakasala,340

12,Mughlai Hyderabadi (Kachchi variant),India,Mutton,3,Basmati,480

;

run;

proc print;run;

Output:

ObsBiryani_IDBiryani_NameCountryMeat_TypeRice_TypeSpice_LevelPrice_INR
11Hyderabadi Dum BiryaniIndiaMuttonBasmatiHot420
22Kacchi BiryaniBangladeshMuttonBasmatiHot380
33Ambur BiryaniIndiaChickenShort-GrainMedium220
44Beary BiryaniIndiaBeefParboiledHot250
55Thalassery BiryaniIndiaChickenJeerakasalaMedium300
66Lucknowi (Awadhi) BiryaniIndiaMuttonBasmatiMedium450
77Tehari Vegetarian BiryaniPakistanVegetarianLong-GrainMild150
88Thai-style Seafood BiryaniThailandFishLong-GrainMedium320
99Calcutta BiryaniIndiaChickenBasmatiMedium200
1010Sindhi BiryaniPakistanBeefBasmatiVery Hot360
1111Malabar BiryaniIndiaChickenJeerakasalaHot340
1212Mughlai Hyderabadi (Kachchi variant)IndiaMuttonBasmatiHot480


3) Quick metadata check

PURPOSE: Show dataset structure and variable attributes for QC

proc contents data=biryani_master varnum;

  title "PROC CONTENTS: Biryani Master - Metadata and Attributes";

run;

Output:

PROC CONTENTS: Biryani Master - Metadata and Attributes

The CONTENTS Procedure

Data Set NameWORK.BIRYANI_MASTERObservations12
Member TypeDATAVariables7
EngineV9Indexes0
Created09/08/2025 18:02:10Observation Length128
Last Modified09/08/2025 18:02:10Deleted Observations0
Protection CompressedNO
Data Set Type SortedNO
Label   
Data RepresentationSOLARIS_X86_64, LINUX_X86_64, ALPHA_TRU64, LINUX_IA64  
Encodingutf-8 Unicode (UTF-8)  
Engine/Host Dependent Information
Data Set Page Size131072
Number of Data Set Pages1
First Data Page1
Max Obs per Page1022
Obs in First Data Page12
Number of Data Set Repairs0
Filename/saswork/SAS_work225800008908_odaws01-apse1-2.oda.sas.com/SAS_work65CF00008908_odaws01-apse1-2.oda.sas.com/biryani_master.sas7bdat
Release Created9.0401M8
Host CreatedLinux
Inode Number1091090
Access Permissionrw-r--r--
Owner Nameu63247146
File Size256KB
File Size (bytes)262144
Variables in Creation Order
#VariableTypeLenFormat
1Biryani_IDNum8 
2Biryani_NameChar40 
3CountryChar30 
4Meat_TypeChar12 
5Rice_TypeChar20 
6Spice_LevelNum8SLEVEL.
7Price_INRNum8 

4) Display full dataset

PURPOSE: Print the dataset to inspect values visually

proc print data=biryani_master label noobs;

  title "PROC PRINT: Full Biryani Dataset";

  var Biryani_ID Biryani_Name Country Meat_Type Spice_Level Rice_Type Price_INR;

run;

Output:

PROC PRINT: Full Biryani Dataset

Biryani_IDBiryani_NameCountryMeat_TypeSpice_LevelRice_TypePrice_INR
1Hyderabadi Dum BiryaniIndiaMuttonHotBasmati420
2Kacchi BiryaniBangladeshMuttonHotBasmati380
3Ambur BiryaniIndiaChickenMediumShort-Grain220
4Beary BiryaniIndiaBeefHotParboiled250
5Thalassery BiryaniIndiaChickenMediumJeerakasala300
6Lucknowi (Awadhi) BiryaniIndiaMuttonMediumBasmati450
7Tehari Vegetarian BiryaniPakistanVegetarianMildLong-Grain150
8Thai-style Seafood BiryaniThailandFishMediumLong-Grain320
9Calcutta BiryaniIndiaChickenMediumBasmati200
10Sindhi BiryaniPakistanBeefVery HotBasmati360
11Malabar BiryaniIndiaChickenHotJeerakasala340
12Mughlai Hyderabadi (Kachchi variant)IndiaMuttonHotBasmati480

5) Numeric summary: price statistics

PURPOSE: Use PROC MEANS to compute count, mean, std, min, max for Price_INR

proc means data=biryani_master n mean std min max maxdec=2;

  var Price_INR Spice_Level;

  title "PROC MEANS: Price and Spice Level Summary";

run;

Output:

PROC MEANS: Price and Spice Level Summary

The MEANS Procedure

VariableNMeanStd DevMinimumMaximum
Price_INR
Spice_Level
12
12
322.50
2.50
102.97
0.80
150.00
1.00
480.00
4.00

6) Frequency tables for categorical variables

PURPOSE: Use PROC FREQ to get frequency distribution of Meat_Type and Spice_Level

proc freq data=biryani_master;

  tables Meat_Type Spice_Level / nocum nopercent;

  format Spice_Level slevel.;

  title "PROC FREQ: Meat Type and Spice Level Distribution";

run;

Output:

PROC FREQ: Meat Type and Spice Level Distribution

The FREQ Procedure

Meat_TypeFrequency
Beef2
Chicken4
Fish1
Mutton4
Vegetarian1
Spice_LevelFrequency
Mild1
Medium5
Hot5
Very Hot1

7) Sort dataset by Price descending

PURPOSE: Use PROC SORT to prepare ordered dataset for reporting

proc sort data=biryani_master out=biryani_sorted;

  by descending Price_INR;

run;

proc print;run;

Output:

ObsBiryani_IDBiryani_NameCountryMeat_TypeRice_TypeSpice_LevelPrice_INR
112Mughlai Hyderabadi (Kachchi variant)IndiaMuttonBasmatiHot480
26Lucknowi (Awadhi) BiryaniIndiaMuttonBasmatiMedium450
31Hyderabadi Dum BiryaniIndiaMuttonBasmatiHot420
42Kacchi BiryaniBangladeshMuttonBasmatiHot380
510Sindhi BiryaniPakistanBeefBasmatiVery Hot360
611Malabar BiryaniIndiaChickenJeerakasalaHot340
78Thai-style Seafood BiryaniThailandFishLong-GrainMedium320
85Thalassery BiryaniIndiaChickenJeerakasalaMedium300
94Beary BiryaniIndiaBeefParboiledHot250
103Ambur BiryaniIndiaChickenShort-GrainMedium220
119Calcutta BiryaniIndiaChickenBasmatiMedium200
127Tehari Vegetarian BiryaniPakistanVegetarianLong-GrainMild150


8) Use PROC SQL to create a summary table: average price by Meat_Type

PURPOSE: Demonstrate SQL aggregation to compute avg price per meat type

proc sql;

  create table avg_price_by_meat as

  select Meat_Type,

         count(*) as N,

         round(mean(Price_INR),0.01) as Avg_Price format=8.2,

         min(Price_INR) as Min_Price,

         max(Price_INR) as Max_Price

  from biryani_master

  group by Meat_Type

  order by Avg_Price desc;

quit;

proc print data=avg_price_by_meat noobs;

  title "PROC SQL: Average Price by Meat Type";

run;

Output:

PROC SQL: Average Price by Meat Type

Meat_TypeNAvg_PriceMin_PriceMax_Price
Mutton4432.50380480
Fish1320.00320320
Beef2305.00250360
Chicken4265.00200340
Vegetarian1150.00150150

9) TRANSPOSE example: pivot Price by Country

PURPOSE: Use PROC TRANSPOSE to pivot table of prices for a country-wise view

proc transpose data=biryani_master out=price_by_country prefix=Price_;

  by Country notsorted;

  id Biryani_ID;

  var Price_INR;

run;

proc print data=price_by_country noobs;

  title "PROC TRANSPOSE: Price by Country (pivoted by Biryani_ID)";

run;

Output:

PROC TRANSPOSE: Price by Country (pivoted by Biryani_ID)

Country_NAME_Price_1Price_2Price_3Price_4Price_5Price_6Price_7Price_8Price_9Price_10Price_11Price_12
IndiaPrice_INR420...........
BangladeshPrice_INR.380..........
IndiaPrice_INR..220250300450......
PakistanPrice_INR......150.....
ThailandPrice_INR.......320....
IndiaPrice_INR........200...
PakistanPrice_INR.........360..
IndiaPrice_INR..........340480

10) PROC REPORT: Advanced tabular report with computed column

PURPOSE: Use PROC REPORT to display custom report and compute price category

proc format;

  value pcat

    low - 199 = 'Budget'

    200 - 349 = 'Mid'

    350 - high = 'Premium';

run;

Log:

NOTE: Format PCAT has been output.

proc report data=biryani_sorted nowd;

  column Biryani_ID Biryani_Name Country Meat_Type Spice_Level Rice_Type Price_INR price_cat;

  define price_cat / computed 'Price Category';

  compute price_cat;

    if Price_INR < 200 then price_cat = 'Budget';

    else if 200 <= Price_INR < 350 then price_cat = 'Mid';

    else price_cat = 'Premium';

  endcomp;

  title "PROC REPORT: Biryani Report with Price Category";

run;

Output:

PROC REPORT: Biryani Report with Price Category

Biryani_IDBiryani_NameCountryMeat_TypeSpice_LevelRice_TypePrice_INRPrice Category
12Mughlai Hyderabadi (Kachchi variant)IndiaMuttonHotBasmati480.
6Lucknowi (Awadhi) BiryaniIndiaMuttonMediumBasmati450.
1Hyderabadi Dum BiryaniIndiaMuttonHotBasmati420.
2Kacchi BiryaniBangladeshMuttonHotBasmati380.
10Sindhi BiryaniPakistanBeefVery HotBasmati360.
11Malabar BiryaniIndiaChickenHotJeerakasala340.
8Thai-style Seafood BiryaniThailandFishMediumLong-Grain320.
5Thalassery BiryaniIndiaChickenMediumJeerakasala300.
4Beary BiryaniIndiaBeefHotParboiled250.
3Ambur BiryaniIndiaChickenMediumShort-Grain220.
9Calcutta BiryaniIndiaChickenMediumBasmati200.
7Tehari Vegetarian BiryaniPakistanVegetarianMildLong-Grain150.

11) PROC TABULATE: Cross-tab summary (Meat_Type x Spice_Level)

PURPOSE: Use PROC TABULATE to provide a compact cross-tab of counts and mean prices

proc tabulate data=biryani_master;

  class Meat_Type Spice_Level;

  var Price_INR;

  table Meat_Type,

        Spice_Level*(Price_INR*(n='Count' mean='AvgPrice'*f=8.2)) / rts=20;

  format Spice_Level slevel.;

  title "PROC TABULATE: Meat Type by Spice Level (count & mean price)";

run;

Output:

PROC TABULATE: Meat Type by Spice Level (count & mean price)

 Spice_Level
MildMediumHotVery Hot
Price_INRPrice_INRPrice_INRPrice_INR
CountAvgPriceCountAvgPriceCountAvgPriceCountAvgPrice
Meat_Type....1250.001360.00
Beef
Chicken..3240.001340.00..
Fish..1320.00....
Mutton..1450.003426.67..
Vegetarian1150.00......

12) PROC UNIVARIATE: Check distribution of price for outliers

PURPOSE: Use PROC UNIVARIATE to examine price distribution and check outliers

proc univariate data=biryani_master cibasic;

  var Price_INR;

  title "PROC UNIVARIATE: Price Distribution and Outlier Check";

run;

Output:

PROC UNIVARIATE: Price Distribution and Outlier Check

The UNIVARIATE Procedure

Variable: Price_INR

Moments
N12Sum Weights12
Mean322.5Sum Observations3870
Std Deviation102.967338Variance10602.2727
Skewness-0.1284958Kurtosis-0.9046522
Uncorrected SS1364700Corrected SS116625
Coeff Variation31.9278568Std Error Mean29.7241102
Basic Statistical Measures
LocationVariability
Mean322.5000Std Deviation102.96734
Median330.0000Variance10602
Mode.Range330.00000
  Interquartile Range165.00000
Basic Confidence Limits Assuming Normality
ParameterEstimate95% Confidence Limits
Mean322.50000257.07767387.92233
Std Deviation102.9673472.94156174.82598
Variance10602532030564
Tests for Location: Mu0=0
TestStatisticp Value
Student's tt10.84978Pr > |t|<.0001
SignM6Pr >= |M|0.0005
Signed RankS39Pr >= |S|0.0005
Quantiles (Definition 5)
LevelQuantile
100% Max480
99%480
95%480
90%450
75% Q3400
50% Median330
25% Q1235
10%200
5%150
1%150
0% Min150
Extreme Observations
LowestHighest
ValueObsValueObs
150736010
20093802
22034201
25044506
300548012

13) Simple visualization: bar chart of counts by Meat_Type (requires ODS graphics)

PURPOSE: Use PROC SGPLOT to visualize counts of biryanis by meat type

proc sgplot data=biryani_master;

  vbar Meat_Type / datalabel;

  title "PROC SGPLOT: Count of Biryani Types by Meat_Type";

run;

Output:



14) MACRO: dynamic summary by any categorical variable

PURPOSE: Macro to compute frequency and average price for a given categorical variable

%macro summary_by(catvar=);

  /* single-line purpose: compute counts and average price by a categorical variable */

  proc sql;

    create table summary_&catvar as

    select &catvar,

           count(*) as N,

           round(mean(Price_INR),0.01) as AvgPrice format=8.2

    from biryani_master

    group by &catvar

    order by N desc;

  quit;

  proc print data=summary_&catvar noobs;

    title "Summary by &catvar";

  run;

%mend summary_by;


%summary_by(catvar=Country);

Output:

Summary by Country

CountryNAvgPrice
India8332.50
Pakistan2255.00
Bangladesh1380.00
Thailand1320.00

%summary_by(catvar=Spice_Level);

Output:

Summary by Spice_Level

Spice_LevelNAvgPrice
Hot5374.00
Medium5298.00
Mild1150.00
Very Hot1360.00

15) Basic QC: check for missing values and duplicates

PURPOSE: Run checks for missingness and duplicate Biryani_IDs

proc sql;

  select sum(case when Biryani_ID is null then 1 else 0 end) as missing_id,

         sum(case when Biryani_Name is null then 1 else 0 end) as missing_name,

         count(distinct Biryani_ID) as distinct_ids,

         count(*) as total_rows

  from biryani_master;

quit;

proc sort data=biryani_master out=dup_check nodupkey dupout=dup_biryani;

  by Biryani_ID;

run;

proc print data=dup_biryani noobs;

  title "Duplicate Biryani_IDs (should be empty)";

run;

Output:

missing_idmissing_namedistinct_idstotal_rows
001212




To Visit My Previous E-Commerce Dataset:Click Here
To Visit My Previous Length,Input,Retain Statements:Click Here
To Visit My Previous Urban Traffic Dataset:Click Here
To Visit My Previous Home Energy Consumption Dataset:Click Here



Follow Us On : 


 


--- FOLLOW OUR BLOG FOR MORE INFORMATION.

--->PLEASE DO COMMENTS AND SHARE OUR BLOG.


Comments

Popular posts from this blog

409.Can We Build a Reliable Emergency Services Analytics & Fraud Detection System in SAS While Identifying and Fixing Intentional Errors?

397.If a satellite has excellent signal strength but very high latency, can it still deliver good quality communication? Why or why not?A Sas Study

401.How Efficient Are Global Data Centers? A Complete SAS Analytics Study