313.Are We Losing Wildlife Faster Than We Think? – Animal Conservation Analysis Using SAS

Are We Losing Wildlife Faster Than We Think? – Animal Conservation Analysis Using SAS

options fmtsearch=(work.formats) nocenter nodate nonumber;

1. Proc Format

proc format library=work.formats;

  /* Standardize continent labels */

  value $continentfmt

    'AF' = 'Africa'

    'AS' = 'Asia'

    'EU' = 'Europe'

    'NA' = 'North America'

    'SA' = 'South America'

    'OC' = 'Oceania'

    'AN' = 'Antarctica'

    other = 'Unknown';

LOG:

NOTE: Format $CONTINENTFMT has been output.

  /* Diet categories */

  value $dietfmt

    'Herbivore'   = 'Herbivore'

    'Carnivore'   = 'Carnivore'

    'Omnivore'    = 'Omnivore'

    'Insectivore' = 'Insectivore'

    other         = 'Other/Unknown';

LOG:

NOTE: Format $DIETFMT has been output.

  /* Conservation status  */

  value $consfmt

    'LC' = 'Least Concern'

    'NT' = 'Near Threatened'

    'VU' = 'Vulnerable'

    'EN' = 'Endangered'

    'CR' = 'Critically Endangered'

    'EW' = 'Extinct in Wild'

    'EX' = 'Extinct'

    other = 'Unknown';

LOG:

NOTE: Format $CONSFMT has been output.

  /* Population bins using numeric format (for PROC FREQ / charts) */

  value popcat

    low - <1000 = 'Tiny (<1k)'

    1000 - <10000 = 'Small (1k-10k)'

    10000 - <100000 = 'Medium (10k-100k)'

    100000 - <1000000 = 'Large (100k-1M)'

    1000000 - high = 'Very Large (>1M)';

run;

LOG:

NOTE: Format POPCAT has been output.

2. Create the dataset using PROC SQL 

proc sql;

    create table work.animals as

    select 

        "African Elephant"      as Species,

        "AF"                              as Continent,

        415000                            as Population,

        60                                    as Lifespan,

        "Herbivore"                  as Diet,

        "EN"                              as Conservation_Status,

        '15FEB2022'd               as Last_Survey_Date,

        '01JAN2022'd               as Population_Estimate_Date

    from sashelp.class(obs=1)

    union all

    select "Bengal Tiger",        "AS", 2500,     15, "Carnivore", "EN", '10DEC2023'd, '01JAN2023'd

    from sashelp.class(obs=1)

    union all

    select "Giant Panda",         "AS", 1864,     20, "Herbivore", "VU", '05MAY2021'd, '01JAN2021'd

    from sashelp.class(obs=1)

    union all

    select "Blue Whale",          "OC", 10000,    90, "Carnivore", "EN", '20JUN2020'd, '01JAN2020'd

    from sashelp.class(obs=1)

    union all

    select "Red Kangaroo",        "OC", 11500000, 22, "Herbivore", "LC", '12NOV2022'd, '01JAN2022'd

    from sashelp.class(obs=1)

    union all

    select "Galapagos Tortoise",  "SA", 15000,    100, "Herbivore","EN",'02APR2019'd,'01JAN2019'd

    from sashelp.class(obs=1)

    union all

    select "Polar Bear",          "AN", 26000,    25, "Carnivore", "VU",'30SEP2022'd,'01JAN2022'd

    from sashelp.class(obs=1)

    union all

    select "Grizzly Bear",        "NA", 55000,    25, "Omnivore", "LC",'18JUL2023'd,'01JAN2023'd

    from sashelp.class(obs=1)

    union all

    select "Emperor Penguin",     "AN", 595000,   20, "Carnivore","NT",'05AUG2021'd,'01JAN2021'd

   from sashelp.class(obs=1)

    union all

    select "Mountain Gorilla",    "AF", 1005,     35, "Herbivore","CR",'22NOV2023'd,'01JAN2023'd

    from sashelp.class(obs=1)

    union all

    select "Komodo Dragon",       "OC", 3000,     30, "Carnivore","VU",'11MAR2022'd,'01JAN2022'd

    from sashelp.class(obs=1)

    union all

    select "European Hedgehog",   "EU", 1200000,  8,  "Omnivore","LC",'03OCT2023'd,'01JAN2023'd

    from sashelp.class(obs=1)

    ;

quit;

Proc print data=work.animals;

run;

OUTPUT:

ObsSpeciesContinentPopulationLifespanDietConservation_StatusLast_Survey_DatePopulation_Estimate_Date
1African ElephantAF41500060HerbivoreEN2269122646
2Bengal TigerAS250015CarnivoreEN2335423011
3Giant PandaAS186420HerbivoreVU2240522281
4Blue WhaleOC1000090CarnivoreEN2208621915
5Red KangarooOC1150000022HerbivoreLC2296122646
6Galapagos TortoiseSA15000100HerbivoreEN2164121550
7Polar BearAN2600025CarnivoreVU2291822646
8Grizzly BearNA5500025OmnivoreLC2320923011
9Emperor PenguinAN59500020CarnivoreNT2249722281
10Mountain GorillaAF100535HerbivoreCR2333623011
11Komodo DragonOC300030CarnivoreVU2271522646
12European HedgehogEU12000008OmnivoreLC2328623011


3. Add labels and formats 

data work.animals;

  set work.animals;

  label Species = "Species (Common Name)"

        Continent = "Continent Code"

        Population = "Estimated Population (count)"

        Lifespan = "Average Lifespan (years)"

        Diet = "Primary Diet"

        Conservation_Status = "Conservation Status (code)"

        Last_Survey_Date = "Last Survey Date"

        Population_Estimate_Date = "Population Estimate Date";

  format Continent $continentfmt. Diet $dietfmt. Conservation_Status $consfmt.

         Population popcat. Last_Survey_Date date9. Population_Estimate_Date date9.;

run;

proc print data=work.animals (obs=12) label noobs;

  title "WORK.ANIMALS - First 12 Observations";

run;

OUTPUT:

WORK.ANIMALS - First 12 Observations

Species (Common Name)Continent CodeEstimated Population (count)Average Lifespan (years)Primary DietConservation Status (code)Last Survey DatePopulation Estimate Date
African ElephantAfricaLarge (100k-1M)60HerbivoreEndangered15FEB202201JAN2022
Bengal TigerAsiaSmall (1k-10k)15CarnivoreEndangered10DEC202301JAN2023
Giant PandaAsiaSmall (1k-10k)20HerbivoreVulnerable05MAY202101JAN2021
Blue WhaleOceaniaMedium (10k-100k)90CarnivoreEndangered20JUN202001JAN2020
Red KangarooOceaniaVery Large (>1M)22HerbivoreLeast Concern12NOV202201JAN2022
Galapagos TortoiseSouth AmericaMedium (10k-100k)100HerbivoreEndangered02APR201901JAN2019
Polar BearAntarcticaMedium (10k-100k)25CarnivoreVulnerable30SEP202201JAN2022
Grizzly BearNorth AmericaMedium (10k-100k)25OmnivoreLeast Concern18JUL202301JAN2023
Emperor PenguinAntarcticaLarge (100k-1M)20CarnivoreNear Threatened05AUG202101JAN2021
Mountain GorillaAfricaSmall (1k-10k)35HerbivoreCritically Endangered22NOV202301JAN2023
Komodo DragonOceaniaSmall (1k-10k)30CarnivoreVulnerable11MAR202201JAN2022
European HedgehogEuropeVery Large (>1M)8OmnivoreLeast Concern03OCT202301JAN2023

4. Frequency distributions 

proc freq data=work.animals;

  tables Continent Conservation_Status Diet Population / nocum nopercent;

  title "Frequencies of Continent, Status, Diet and Population Bins";

run;

OUTPUT:

Frequencies of Continent, Status, Diet and Population Bins

The FREQ Procedure

Continent Code
ContinentFrequency
Africa2
Antarctica2
Asia2
Europe1
North America1
Oceania3
South America1
Conservation Status (code)
Conservation_StatusFrequency
Critically Endangered1
Endangered4
Least Concern3
Near Threatened1
Vulnerable3
Primary Diet
DietFrequency
Carnivore5
Herbivore5
Omnivore2
Estimated Population (count)
PopulationFrequency
Small (1k-10k)4
Medium (10k-100k)4
Large (100k-1M)2
Very Large (>1M)2

5. Numeric summaries 

proc means data=work.animals n mean std min max median maxdec=1;

  var Population Lifespan;

  title "Numeric Summary: Population & Lifespan";

run;

OUTPUT:

Numeric Summary: Population & Lifespan

The MEANS Procedure

VariableLabelNMeanStd DevMinimumMaximumMedian
Population
Lifespan
Estimated Population (count)
Average Lifespan (years)
12
12
1152030.8
37.5
3279331.9
29.8
1005.0
8.0
11500000.0
100.0
20500.0
25.0

6. Univariate diagnostics for Population 

proc univariate data=work.animals;

  var Population;

  histogram Population / midpoints=0 to 12000000 by 1000000;

  inset mean std min max / position=ne;

  title "Population Distribution (Univariate)";

run;

OUTPUT:

Population Distribution (Univariate)

The UNIVARIATE Procedure

Variable: Population (Estimated Population (count))

Moments
N12Sum Weights12
Mean1152030.75Sum Observations13824369
Std Deviation3279331.94Variance1.0754E13
Skewness3.38941694Kurtosis11.6086323
Uncorrected SS1.3422E14Corrected SS1.18294E14
Coeff Variation284.656632Std Error Mean946661.589
Basic Statistical Measures
LocationVariability
Mean1152031Std Deviation3279332
Median20500Variance1.0754E13
Mode.Range11498995
  Interquartile Range502250
Tests for Location: Mu0=0
TestStatisticp Value
Student's tt1.21694Pr > |t|0.2491
SignM6Pr >= |M|0.0005
Signed RankS39Pr >= |S|0.0005
Quantiles (Definition 5)
LevelQuantile
100% Max11500000
99%11500000
95%11500000
90%1200000
75% Q3505000
50% Median20500
25% Q12750
10%1864
5%1005
1%1005
0% Min1005
Extreme Observations
LowestHighest
ValueObsValueObs
100510550008
186434150001
250025950009
300011120000012
100004115000005

Population Distribution (Univariate)

The UNIVARIATE Procedure

Histogram for Population

7. Tabulate cross-tab summary by Continent and Conservation_Status 

proc tabulate data=work.animals format=8.0;

  class Continent Conservation_Status;

  var Population;

  table Continent all,

        Conservation_Status * (n='Count' colpctn='Pct within Continent') / box='Continent by Conservation Status';

  title "Tabulation: Continent x Conservation Status";

run;

OUTPUT:

Tabulation: Continent x Conservation Status

Continent by Conservation StatusConservation Status (code)
Critically EndangeredEndangeredLeast ConcernNear ThreatenedVulnerable
CountPct within ContinentCountPct within ContinentCountPct within ContinentCountPct within ContinentCountPct within Continent
Continent Code1100125......
Africa
Antarctica......1100133
Asia..125....133
Europe....133....
North America....133....
Oceania..125133..133
South America..125......
All11004100310011003100

8. Generate a basic chart using PROC GCHART (bar chart) 

goptions reset=all device=png htext=1.2;

proc gchart data=work.animals;

  vbar Conservation_Status / discrete sumvar=Population subgroup=Continent

       raxis=axis1 maxis=axis2

       coutline=black

       midpoints='LC' 'NT' 'VU' 'EN' 'CR' 'EW' 'EX';

  title "Total Population by Conservation Status (bars) with Continent subgrouping";

run;

quit;

OUTPUT:

Bar chart of Conservation_Status

9. Macro: create conservation summary dataset and print + chart 

%macro conservation_report(outds=work.cons_summary, chart=YES, minpop=0);

  /* Aggregate counts and population sums by status and continent */

  proc sql;

    create table &outds as

    select Conservation_Status,

           put(Conservation_Status,$consfmt.) as Status_Label,

           Continent,

           put(Continent,$continentfmt.) as Continent_Label,

           count(*) as Species_Count,

           sum(Population) as Total_Population,

           mean(Lifespan) as Mean_Lifespan

    from work.animals

    where Population >= &minpop

    group by Conservation_Status, Continent

    order by Conservation_Status, Continent;

  quit;


  title "Conservation Summary (Population >= &minpop)";

  proc print data=&outds noobs label;

    var Conservation_Status Status_Label Continent_Label Species_Count Total_Population Mean_Lifespan;

  run;


  %if %upcase(&chart)=YES %then %do;

    /* simple pie of species counts by conservation status */

    proc gchart data=&outds;

      pie Conservation_Status / sumvar=Species_Count

          other=0

          percent=outside

          value=none;

      title "Species Count by Conservation Status (Pie)";

    run;

    quit;

  %end;

%mend conservation_report;


%conservation_report(outds=work.cons_summary_all, chart=YES, minpop=0);

OUTPUT:

Conservation Summary (Population >= 0)

Conservation Status (code)Status_LabelContinent_LabelSpecies_CountTotal_PopulationMean_Lifespan
Critically EndangeredCritically EndangeredAfrica1100535
EndangeredEndangeredAfrica141500060
EndangeredEndangeredAsia1250015
EndangeredEndangeredOceania11000090
EndangeredEndangeredSouth America115000100
Least ConcernLeast ConcernEurope112000008
Least ConcernLeast ConcernNorth America15500025
Least ConcernLeast ConcernOceania11150000022
Near ThreatenedNear ThreatenedAntarctica159500020
VulnerableVulnerableAntarctica12600025
VulnerableVulnerableAsia1186420
VulnerableVulnerableOceania1300030

Pie chart of Conservation_Status

10. Macro: Create population bins and produce summary report 

%macro population_binning(in=work.animals, out=work.animals_binned);

  /* create a dataset with population bin labels using the popcat format */

  data &out;

    set &in;

    Population_Category = put(Population, popcat.);

    format Population_Category $30.;

  run;


  proc freq data=&out;

    tables Population_Category / nocum nopercent;

    title "Population Categories (based on popcat format)";

  run;


  proc means data=&out n mean median min max;

    class Population_Category;

    var Population Lifespan;

    title "Summary by Population Category";

  run;

%mend population_binning;


%population_binning(in=work.animals, out=work.animals_binned);

OUTPUT:

Population Categories (based on popcat format)

The FREQ Procedure

Population_CategoryFrequency
Large (100k-1M)2
Medium (10k-100k)4
Small (1k-10k)4
Very Large (>1M)2

Summary by Population Category

The MEANS Procedure

Population_CategoryN ObsVariableLabelNMeanMedianMinimumMaximum
Large (100k-1M)2
Population
Lifespan
Estimated Population (count)
Average Lifespan (years)
2
2
505000.00
40.0000000
505000.00
40.0000000
415000.00
20.0000000
595000.00
60.0000000
Medium (10k-100k)4
Population
Lifespan
Estimated Population (count)
Average Lifespan (years)
4
4
26500.00
60.0000000
20500.00
57.5000000
10000.00
25.0000000
55000.00
100.0000000
Small (1k-10k)4
Population
Lifespan
Estimated Population (count)
Average Lifespan (years)
4
4
2092.25
25.0000000
2182.00
25.0000000
1005.00
15.0000000
3000.00
35.0000000
Very Large (>1M)2
Population
Lifespan
Estimated Population (count)
Average Lifespan (years)
2
2
6350000.00
15.0000000
6350000.00
15.0000000
1200000.00
8.0000000
11500000.00
22.0000000

11.Using PROC REPORT for a clean summary table 

proc report data=work.cons_summary_all nowd;

  columns Status_Label Continent_Label Species_Count Total_Population Mean_Lifespan;

  define Status_Label / group 'Conservation Status';

  define Continent_Label / group 'Continent';

  define Species_Count / analysis 'No. Species';

  define Total_Population / analysis sum format=comma12. 'Total Population';

  define Mean_Lifespan / analysis mean format=6.1 'Avg Lifespan (yrs)';

  title "Formatted Report: Conservation Summary";

run;

OUTPUT:

Formatted Report: Conservation Summary

Conservation StatusContinentNo. SpeciesTotal PopulationAvg Lifespan (yrs)
Critically EndangeredAfrica11,00535.0
EndangeredAfrica1415,00060.0
 Asia12,50015.0
 Oceania110,00090.0
 South America115,000100.0
Least ConcernEurope11,200,0008.0
 North America155,00025.0
 Oceania111,500,00022.0
Near ThreatenedAntarctica1595,00020.0
VulnerableAntarctica126,00025.0
 Asia11,86420.0
 Oceania13,00030.0



To Visit My Previous Different Types Of Oils Dataset:Click Here
To Visit My Previous Different Types Of Series 2025 Dataset:Click Here
To Visit My Previous Analyzing Yoga Asanas Worldwide Dataset:Click Here
To Visit My Previous Analyzing Indian Languages 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

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

383.Which Pharma Distributors Are High-Risk? Can SAS Detect Delays, Temperature Violations, and Fraud?