308.COMPREHENSIVE ANALYSIS OF INDIAN AGRICULTURAL CROPS USING DATA STEP | PROC SQL | MACRO DERIVATIONS | PROC MEANS | PROC FREQ | PROC SGPLOT | PROC SORT

COMPREHENSIVE ANALYSIS OF INDIAN AGRICULTURAL CROPS USING DATA STEP | PROC SQL | MACRO DERIVATIONS | PROC MEANS | PROC FREQ | PROC SGPLOT | PROC SORT

 1. Create the Raw Dataset Using DATA Step

options nocenter validvarname=any;


data work.india_crops;

    infile datalines dlm=',' dsd truncover;

    length Crop_Name $25 Region $20 Season $12 Water_Requirement $15;

    input Crop_Name :$25. Region :$20. Yield_Tons Price_per_Ton Season :$12. 

          Water_Requirement :$15.;

datalines;

Basmati Rice,North India,4200,55000,Kharif,High

Wheat,Northwest India,3800,22000,Rabi,Medium

Sugarcane,South India,9000,32000,Annual,High

Cotton,West India,2800,45000,Kharif,Low

Tea,North East India,2500,160000,Annual,High

Groundnut,South India,3300,48000,Kharif,Low

Maize,Central India,3600,20000,Kharif,Medium

Jowar,West India,3000,18000,Rabi,Low

Soybean,Central India,3400,42000,Kharif,Medium

Turmeric,South India,2900,85000,Annual,Medium

;

run;

proc print data=work.india_crops;

run;

OUTPUT:

ObsCrop_NameRegionSeasonWater_RequirementYield_TonsPrice_per_Ton
1Basmati RiceNorth IndiaKharifHigh420055000
2WheatNorthwest IndiaRabiMedium380022000
3SugarcaneSouth IndiaAnnualHigh900032000
4CottonWest IndiaKharifLow280045000
5TeaNorth East IndiaAnnualHigh2500160000
6GroundnutSouth IndiaKharifLow330048000
7MaizeCentral IndiaKharifMedium360020000
8JowarWest IndiaRabiLow300018000
9SoybeanCentral IndiaKharifMedium340042000
10TurmericSouth IndiaAnnualMedium290085000


2. PROC SQL – Create Derived Variables

proc sql;

    create table work.india_crops_sql as

    select *,

           (Yield_Tons * Price_per_Ton) as Total_Revenue format=comma12.

    from work.india_crops;

quit;

proc print data=work.india_crops_sql;

run;

OUTPUT:

ObsCrop_NameRegionSeasonWater_RequirementYield_TonsPrice_per_TonTotal_Revenue
1Basmati RiceNorth IndiaKharifHigh420055000231,000,000
2WheatNorthwest IndiaRabiMedium38002200083,600,000
3SugarcaneSouth IndiaAnnualHigh900032000288,000,000
4CottonWest IndiaKharifLow280045000126,000,000
5TeaNorth East IndiaAnnualHigh2500160000400,000,000
6GroundnutSouth IndiaKharifLow330048000158,400,000
7MaizeCentral IndiaKharifMedium36002000072,000,000
8JowarWest IndiaRabiLow30001800054,000,000
9SoybeanCentral IndiaKharifMedium340042000142,800,000
10TurmericSouth IndiaAnnualMedium290085000246,500,000


3. Macro for Repetitive Derivation

%macro yieldcat(input=, output=);

    data &output.;

        set &input.;

        length Yield_Category $15;

        if Yield_Tons >= 4000 then Yield_Category = "HIGH_YIELD";

        else if Yield_Tons >= 3000 then Yield_Category = "MEDIUM_YIELD";

        else Yield_Category = "LOW_YIELD";

    run;

    proc print data=&output;

run;

%mend;


%yieldcat(input=work.india_crops_sql, output=work.crops_final);

OUTPUT:

ObsCrop_NameRegionSeasonWater_RequirementYield_TonsPrice_per_TonTotal_RevenueYield_Category
1Basmati RiceNorth IndiaKharifHigh420055000231,000,000HIGH_YIELD
2WheatNorthwest IndiaRabiMedium38002200083,600,000MEDIUM_YIELD
3SugarcaneSouth IndiaAnnualHigh900032000288,000,000HIGH_YIELD
4CottonWest IndiaKharifLow280045000126,000,000LOW_YIELD
5TeaNorth East IndiaAnnualHigh2500160000400,000,000LOW_YIELD
6GroundnutSouth IndiaKharifLow330048000158,400,000MEDIUM_YIELD
7MaizeCentral IndiaKharifMedium36002000072,000,000MEDIUM_YIELD
8JowarWest IndiaRabiLow30001800054,000,000MEDIUM_YIELD
9SoybeanCentral IndiaKharifMedium340042000142,800,000MEDIUM_YIELD
10TurmericSouth IndiaAnnualMedium290085000246,500,000LOW_YIELD


4. Summary Statistics Using PROC MEANS

proc means data=work.crops_final mean min max maxdec=2;

    var Yield_Tons Price_per_Ton Total_Revenue;

run;

OUTPUT:

The MEANS Procedure

VariableMeanMinimumMaximum
Yield_Tons
Price_per_Ton
Total_Revenue
3850.00
52700.00
180230000.00
2500.00
18000.00
54000000.00
9000.00
160000.00
400000000.00

5. Frequency Tables Using PROC FREQ

proc freq data=work.crops_final;

    tables Region Season Water_Requirement Yield_Category;

run;

OUTPUT:

The FREQ Procedure

RegionFrequencyPercentCumulative
Frequency
Cumulative
Percent
Central India220.00220.00
North East India110.00330.00
North India110.00440.00
Northwest India110.00550.00
South India330.00880.00
West India220.0010100.00
SeasonFrequencyPercentCumulative
Frequency
Cumulative
Percent
Annual330.00330.00
Kharif550.00880.00
Rabi220.0010100.00
Water_RequirementFrequencyPercentCumulative
Frequency
Cumulative
Percent
High330.00330.00
Low330.00660.00
Medium440.0010100.00
Yield_CategoryFrequencyPercentCumulative
Frequency
Cumulative
Percent
HIGH_YIELD220.00220.00
LOW_YIELD330.00550.00
MEDIUM_YIELD550.0010100.00

6. Visualization Using PROC SGPLOT

Plot 1: Yield by Crop

proc sgplot data=work.crops_final;

    vbar Crop_Name / response=Yield_Tons datalabel;

    xaxis display=(nolabel);

    yaxis label="Yield (Tons)";

    title "Yield Comparison of Agricultural Crops in India";

run;

OUTPUT:

The SGPlot Procedure


Plot 2: Price per Ton by Region

proc sgplot data=work.crops_final;

    scatter x=Region y=Price_per_Ton / group=Season datalabel=Crop_Name;

    title "Price per Ton by Region and Season";

run;

OUTPUT:

The SGPlot Procedure


7. Sort Dataset by Total Revenue

proc sort data=work.crops_final out=work.crops_sorted;

    by descending Total_Revenue;

run;

proc print data=work.crops_sorted;

    title "Crops Sorted by Total Revenue (Highest to Lowest)";

run;

OUTPUT:

Crops Sorted by Total Revenue (Highest to Lowest)

ObsCrop_NameRegionSeasonWater_RequirementYield_TonsPrice_per_TonTotal_RevenueYield_Category
1TeaNorth East IndiaAnnualHigh2500160000400,000,000LOW_YIELD
2SugarcaneSouth IndiaAnnualHigh900032000288,000,000HIGH_YIELD
3TurmericSouth IndiaAnnualMedium290085000246,500,000LOW_YIELD
4Basmati RiceNorth IndiaKharifHigh420055000231,000,000HIGH_YIELD
5GroundnutSouth IndiaKharifLow330048000158,400,000MEDIUM_YIELD
6SoybeanCentral IndiaKharifMedium340042000142,800,000MEDIUM_YIELD
7CottonWest IndiaKharifLow280045000126,000,000LOW_YIELD
8WheatNorthwest IndiaRabiMedium38002200083,600,000MEDIUM_YIELD
9MaizeCentral IndiaKharifMedium36002000072,000,000MEDIUM_YIELD
10JowarWest IndiaRabiLow30001800054,000,000MEDIUM_YIELD

8. Generate a Boxplot of Yield by Season

proc sgplot data=work.crops_final;

    vbox Yield_Tons / category=Season;

    title "Distribution of Crop Yield Across Seasons";

run;

OUTPUT:
The SGPlot Procedure




To Visit My Previous Electronic Data Analysis:Click Here
To Visit My Previous IPS Toppers Dataset:Click Here
To Visit My Previous Global Money Loan Trends Dataset:Click Here
To Visit My Previous Statewise Population Analysis: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