MARINE LIFE DATASET CREATION USING PROC SQL | PROC MEANS | PROC UNIVARIATE | PROC FREQ | PROC SGPLOT WITH MACRO-BASED EXTINCTION RISK CLASSIFICATION AND ADVANCED DATE FUNCTIONS (INTCK | INTNX | YEAR | MONTH)
options nocenter;
1. Creating the Marine Life Dataset
data marine_life_raw;
length Species $25 Ocean $10 Diet_Type $15;
format First_Recorded Protection_Start Last_Survey_Date date9.;
input Species $ Ocean $ Min_Depth Max_Depth Lifespan Diet_Type $ Risk_Score
First_Recorded :date9. Protection_Start :date9. Last_Survey_Date :date9.;
/* Depth range in meters */
Depth_Range = Max_Depth - Min_Depth;
datalines;
Blue_Whale Pacific 0 500 80 Filter_Feeder 4.5 01JAN1960 01JAN1986 15JUL2024
Great_White_Shark Atlantic 0 1200 70 Carnivore 3.8 01JAN1975 01JAN1991 20AUG2023
Clownfish Pacific 1 50 10 Omnivore 1.8 01JAN1985 01JAN2005 10JUN2024
Giant_Squid Atlantic 200 2000 5 Carnivore 2.6 01JAN1990 01JAN2008 05MAY2023
Leatherback_Turtle Indian 0 1000 60 Omnivore 4.2 01JAN1950 01JAN1975 30SEP2024
Manta_Ray Pacific 0 1000 30 Filter_Feeder 2.9 01JAN1980 01JAN2000 01APR2024
Orca Arctic 0 800 50 Carnivore 3.2 01JAN1965 01JAN1985 11NOV2024
Green_Sea_Turtle Atlantic 0 200 70 Herbivore 3.0 01JAN1955 01JAN1970 18MAR2024
Anglerfish Atlantic 300 1500 20 Carnivore 2.0 01JAN1995 01JAN2010 25DEC2023
Coral_Grouper Indian 5 100 15 Carnivore 2.4 01JAN1988 01JAN2002 05JAN2024
Humpback_Whale Southern 0 300 90 Filter_Feeder 3.6 01JAN1952 01JAN1980 08SEP2024
Sea_Otter Pacific 0 40 15 Carnivore 3.4 01JAN1970 01JAN1995 14FEB2024
;
run;
proc print data=marine_life_raw;
run;
OUTPUT:
| Obs | Species | Ocean | Diet_Type | First_Recorded | Protection_Start | Last_Survey_Date | Min_Depth | Max_Depth | Lifespan | Risk_Score | Depth_Range |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Blue_Whale | Pacific | Filter_Feeder | 01JAN1960 | 01JAN1986 | 15JUL2024 | 0 | 500 | 80 | 4.5 | 500 |
| 2 | Great_White_Shark | Atlantic | Carnivore | 01JAN1975 | 01JAN1991 | 20AUG2023 | 0 | 1200 | 70 | 3.8 | 1200 |
| 3 | Clownfish | Pacific | Omnivore | 01JAN1985 | 01JAN2005 | 10JUN2024 | 1 | 50 | 10 | 1.8 | 49 |
| 4 | Giant_Squid | Atlantic | Carnivore | 01JAN1990 | 01JAN2008 | 05MAY2023 | 200 | 2000 | 5 | 2.6 | 1800 |
| 5 | Leatherback_Turtle | Indian | Omnivore | 01JAN1950 | 01JAN1975 | 30SEP2024 | 0 | 1000 | 60 | 4.2 | 1000 |
| 6 | Manta_Ray | Pacific | Filter_Feeder | 01JAN1980 | 01JAN2000 | 01APR2024 | 0 | 1000 | 30 | 2.9 | 1000 |
| 7 | Orca | Arctic | Carnivore | 01JAN1965 | 01JAN1985 | 11NOV2024 | 0 | 800 | 50 | 3.2 | 800 |
| 8 | Green_Sea_Turtle | Atlantic | Herbivore | 01JAN1955 | 01JAN1970 | 18MAR2024 | 0 | 200 | 70 | 3.0 | 200 |
| 9 | Anglerfish | Atlantic | Carnivore | 01JAN1995 | 01JAN2010 | 25DEC2023 | 300 | 1500 | 20 | 2.0 | 1200 |
| 10 | Coral_Grouper | Indian | Carnivore | 01JAN1988 | 01JAN2002 | 05JAN2024 | 5 | 100 | 15 | 2.4 | 95 |
| 11 | Humpback_Whale | Southern | Filter_Feeder | 01JAN1952 | 01JAN1980 | 08SEP2024 | 0 | 300 | 90 | 3.6 | 300 |
| 12 | Sea_Otter | Pacific | Carnivore | 01JAN1970 | 01JAN1995 | 14FEB2024 | 0 | 40 | 15 | 3.4 | 40 |
2. Macro for Extinction Risk Classification
%macro classify_risk(in=marine_life_raw, out=marine_life_risk);
data &out.;
set &in.;
length Extinction_Risk $22;
select;
when (Risk_Score >= 4.5) Extinction_Risk = 'Critically Endangered';
when (Risk_Score >= 3.5) Extinction_Risk = 'Endangered';
when (Risk_Score >= 2.5) Extinction_Risk = 'Vulnerable';
when (Risk_Score >= 1.5) Extinction_Risk = 'Near Threatened';
otherwise Extinction_Risk = 'Least Concern';
end;
run;
proc print data=&out.;
run;
%mend classify_risk;
%classify_risk();
OUTPUT:
| Obs | Species | Ocean | Diet_Type | First_Recorded | Protection_Start | Last_Survey_Date | Min_Depth | Max_Depth | Lifespan | Risk_Score | Depth_Range | Extinction_Risk |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Blue_Whale | Pacific | Filter_Feeder | 01JAN1960 | 01JAN1986 | 15JUL2024 | 0 | 500 | 80 | 4.5 | 500 | Critically Endangered |
| 2 | Great_White_Shark | Atlantic | Carnivore | 01JAN1975 | 01JAN1991 | 20AUG2023 | 0 | 1200 | 70 | 3.8 | 1200 | Endangered |
| 3 | Clownfish | Pacific | Omnivore | 01JAN1985 | 01JAN2005 | 10JUN2024 | 1 | 50 | 10 | 1.8 | 49 | Near Threatened |
| 4 | Giant_Squid | Atlantic | Carnivore | 01JAN1990 | 01JAN2008 | 05MAY2023 | 200 | 2000 | 5 | 2.6 | 1800 | Vulnerable |
| 5 | Leatherback_Turtle | Indian | Omnivore | 01JAN1950 | 01JAN1975 | 30SEP2024 | 0 | 1000 | 60 | 4.2 | 1000 | Endangered |
| 6 | Manta_Ray | Pacific | Filter_Feeder | 01JAN1980 | 01JAN2000 | 01APR2024 | 0 | 1000 | 30 | 2.9 | 1000 | Vulnerable |
| 7 | Orca | Arctic | Carnivore | 01JAN1965 | 01JAN1985 | 11NOV2024 | 0 | 800 | 50 | 3.2 | 800 | Vulnerable |
| 8 | Green_Sea_Turtle | Atlantic | Herbivore | 01JAN1955 | 01JAN1970 | 18MAR2024 | 0 | 200 | 70 | 3.0 | 200 | Vulnerable |
| 9 | Anglerfish | Atlantic | Carnivore | 01JAN1995 | 01JAN2010 | 25DEC2023 | 300 | 1500 | 20 | 2.0 | 1200 | Near Threatened |
| 10 | Coral_Grouper | Indian | Carnivore | 01JAN1988 | 01JAN2002 | 05JAN2024 | 5 | 100 | 15 | 2.4 | 95 | Near Threatened |
| 11 | Humpback_Whale | Southern | Filter_Feeder | 01JAN1952 | 01JAN1980 | 08SEP2024 | 0 | 300 | 90 | 3.6 | 300 | Endangered |
| 12 | Sea_Otter | Pacific | Carnivore | 01JAN1970 | 01JAN1995 | 14FEB2024 | 0 | 40 | 15 | 3.4 | 40 | Vulnerable |
3. Date Calculations with INTCK, INTNX and more
data marine_life_final;
set marine_life_risk;
format Years_Monitored Years_Protected 8.
Next_Survey_Date date9.;
/* 1. Years monitored: from first recorded date until last survey */
Years_Monitored = intck('year', First_Recorded, Last_Survey_Date, 'c');
/* 2. Years under protection: from Protection_Start until today() */
if not missing(Protection_Start) then
Years_Protected = intck('year', Protection_Start, today(), 'c');
else
Years_Protected = .;
/* 3. Next survey: one year after the last survey, same day and month */
Next_Survey_Date = intnx('year', Last_Survey_Date, 1, 'same');
/* 4. Extra date-related variables: year and season of last survey */
First_Year_Recorded = year(First_Recorded);
Last_Survey_Year = year(Last_Survey_Date);
Last_Survey_Month = month(Last_Survey_Date);
length Last_Survey_Season $10;
if Last_Survey_Month in (12,1,2) then Last_Survey_Season = 'Winter';
else if Last_Survey_Month in (3,4,5) then Last_Survey_Season = 'Spring';
else if Last_Survey_Month in (6,7,8) then Last_Survey_Season = 'Summer';
else Last_Survey_Season = 'Autumn';
label
Years_Monitored = 'Years Between First Record and Last Survey'
Years_Protected = 'Years Under Protection Until Today'
Next_Survey_Date = 'Planned Next Survey Date'
First_Year_Recorded = 'Year of First Scientific Record'
Last_Survey_Year = 'Year of Last Survey'
Last_Survey_Season = 'Season of Last Survey';
run;
proc print data=marine_life_final;
run;
OUTPUT:
| Obs | Species | Ocean | Diet_Type | First_Recorded | Protection_Start | Last_Survey_Date | Min_Depth | Max_Depth | Lifespan | Risk_Score | Depth_Range | Extinction_Risk | Years_Monitored | Years_Protected | Next_Survey_Date | First_Year_Recorded | Last_Survey_Year | Last_Survey_Month | Last_Survey_Season |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Blue_Whale | Pacific | Filter_Feeder | 01JAN1960 | 01JAN1986 | 15JUL2024 | 0 | 500 | 80 | 4.5 | 500 | Critically Endangered | 64 | 39 | 15JUL2025 | 1960 | 2024 | 7 | Summer |
| 2 | Great_White_Shark | Atlantic | Carnivore | 01JAN1975 | 01JAN1991 | 20AUG2023 | 0 | 1200 | 70 | 3.8 | 1200 | Endangered | 48 | 34 | 20AUG2024 | 1975 | 2023 | 8 | Summer |
| 3 | Clownfish | Pacific | Omnivore | 01JAN1985 | 01JAN2005 | 10JUN2024 | 1 | 50 | 10 | 1.8 | 49 | Near Threatened | 39 | 20 | 10JUN2025 | 1985 | 2024 | 6 | Summer |
| 4 | Giant_Squid | Atlantic | Carnivore | 01JAN1990 | 01JAN2008 | 05MAY2023 | 200 | 2000 | 5 | 2.6 | 1800 | Vulnerable | 33 | 17 | 05MAY2024 | 1990 | 2023 | 5 | Spring |
| 5 | Leatherback_Turtle | Indian | Omnivore | 01JAN1950 | 01JAN1975 | 30SEP2024 | 0 | 1000 | 60 | 4.2 | 1000 | Endangered | 74 | 50 | 30SEP2025 | 1950 | 2024 | 9 | Autumn |
| 6 | Manta_Ray | Pacific | Filter_Feeder | 01JAN1980 | 01JAN2000 | 01APR2024 | 0 | 1000 | 30 | 2.9 | 1000 | Vulnerable | 44 | 25 | 01APR2025 | 1980 | 2024 | 4 | Spring |
| 7 | Orca | Arctic | Carnivore | 01JAN1965 | 01JAN1985 | 11NOV2024 | 0 | 800 | 50 | 3.2 | 800 | Vulnerable | 59 | 40 | 11NOV2025 | 1965 | 2024 | 11 | Autumn |
| 8 | Green_Sea_Turtle | Atlantic | Herbivore | 01JAN1955 | 01JAN1970 | 18MAR2024 | 0 | 200 | 70 | 3.0 | 200 | Vulnerable | 69 | 55 | 18MAR2025 | 1955 | 2024 | 3 | Spring |
| 9 | Anglerfish | Atlantic | Carnivore | 01JAN1995 | 01JAN2010 | 25DEC2023 | 300 | 1500 | 20 | 2.0 | 1200 | Near Threatened | 28 | 15 | 25DEC2024 | 1995 | 2023 | 12 | Winter |
| 10 | Coral_Grouper | Indian | Carnivore | 01JAN1988 | 01JAN2002 | 05JAN2024 | 5 | 100 | 15 | 2.4 | 95 | Near Threatened | 36 | 23 | 05JAN2025 | 1988 | 2024 | 1 | Winter |
| 11 | Humpback_Whale | Southern | Filter_Feeder | 01JAN1952 | 01JAN1980 | 08SEP2024 | 0 | 300 | 90 | 3.6 | 300 | Endangered | 72 | 45 | 08SEP2025 | 1952 | 2024 | 9 | Autumn |
| 12 | Sea_Otter | Pacific | Carnivore | 01JAN1970 | 01JAN1995 | 14FEB2024 | 0 | 40 | 15 | 3.4 | 40 | Vulnerable | 54 | 30 | 14FEB2025 | 1970 | 2024 | 2 | Winter |
4. Descriptive Statistics with PROC MEANS
proc means data=marine_life_final mean min max std maxdec=1;
class Ocean;
var Lifespan Min_Depth Max_Depth Depth_Range
Years_Monitored Years_Protected;
run;
OUTPUT:
The MEANS Procedure
| Ocean | N Obs | Variable | Label | Mean | Minimum | Maximum | Std Dev |
|---|---|---|---|---|---|---|---|
| Arctic | 1 | Lifespan Min_Depth Max_Depth Depth_Range Years_Monitored Years_Protected | Years Between First Record and Last Survey Years Under Protection Until Today | 50.0 0.0 800.0 800.0 59.0 40.0 | 50.0 0.0 800.0 800.0 59.0 40.0 | 50.0 0.0 800.0 800.0 59.0 40.0 | . . . . . . |
| Atlantic | 4 | Lifespan Min_Depth Max_Depth Depth_Range Years_Monitored Years_Protected | Years Between First Record and Last Survey Years Under Protection Until Today | 41.3 125.0 1225.0 1100.0 44.5 30.3 | 5.0 0.0 200.0 200.0 28.0 15.0 | 70.0 300.0 2000.0 1800.0 69.0 55.0 | 33.8 150.0 758.8 663.3 18.4 18.6 |
| Indian | 2 | Lifespan Min_Depth Max_Depth Depth_Range Years_Monitored Years_Protected | Years Between First Record and Last Survey Years Under Protection Until Today | 37.5 2.5 550.0 547.5 55.0 36.5 | 15.0 0.0 100.0 95.0 36.0 23.0 | 60.0 5.0 1000.0 1000.0 74.0 50.0 | 31.8 3.5 636.4 639.9 26.9 19.1 |
| Pacific | 4 | Lifespan Min_Depth Max_Depth Depth_Range Years_Monitored Years_Protected | Years Between First Record and Last Survey Years Under Protection Until Today | 33.8 0.3 397.5 397.3 50.3 28.5 | 10.0 0.0 40.0 40.0 39.0 20.0 | 80.0 1.0 1000.0 1000.0 64.0 39.0 | 32.0 0.5 455.4 455.6 11.1 8.1 |
| Southern | 1 | Lifespan Min_Depth Max_Depth Depth_Range Years_Monitored Years_Protected | Years Between First Record and Last Survey Years Under Protection Until Today | 90.0 0.0 300.0 300.0 72.0 45.0 | 90.0 0.0 300.0 300.0 72.0 45.0 | 90.0 0.0 300.0 300.0 72.0 45.0 | . . . . . . |
5. Distribution Analysis with PROC UNIVARIATE
proc univariate data=marine_life_final;
var Lifespan Depth_Range Years_Monitored;
histogram Lifespan Depth_Range / kernel;
inset n mean median min max / position=ne;
run;
OUTPUT:
The UNIVARIATE Procedure
Variable: Lifespan
| Moments | |||
|---|---|---|---|
| N | 12 | Sum Weights | 12 |
| Mean | 42.9166667 | Sum Observations | 515 |
| Std Deviation | 30.4106989 | Variance | 924.810606 |
| Skewness | 0.20389178 | Kurtosis | -1.6882325 |
| Uncorrected SS | 32275 | Corrected SS | 10172.9167 |
| Coeff Variation | 70.8598809 | Std Error Mean | 8.77881259 |
| Basic Statistical Measures | |||
|---|---|---|---|
| Location | Variability | ||
| Mean | 42.91667 | Std Deviation | 30.41070 |
| Median | 40.00000 | Variance | 924.81061 |
| Mode | 15.00000 | Range | 85.00000 |
| Interquartile Range | 55.00000 | ||
Note: The mode displayed is the smallest of 2 modes with a count of 2.
| Tests for Location: Mu0=0 | ||||
|---|---|---|---|---|
| Test | Statistic | p Value | ||
| Student's t | t | 4.888664 | Pr > |t| | 0.0005 |
| Sign | M | 6 | Pr >= |M| | 0.0005 |
| Signed Rank | S | 39 | Pr >= |S| | 0.0005 |
| Quantiles (Definition 5) | |
|---|---|
| Level | Quantile |
| 100% Max | 90 |
| 99% | 90 |
| 95% | 90 |
| 90% | 80 |
| 75% Q3 | 70 |
| 50% Median | 40 |
| 25% Q1 | 15 |
| 10% | 10 |
| 5% | 5 |
| 1% | 5 |
| 0% Min | 5 |
| Extreme Observations | |||
|---|---|---|---|
| Lowest | Highest | ||
| Value | Obs | Value | Obs |
| 5 | 4 | 60 | 5 |
| 10 | 3 | 70 | 2 |
| 15 | 12 | 70 | 8 |
| 15 | 10 | 80 | 1 |
| 20 | 9 | 90 | 11 |
The UNIVARIATE Procedure
The UNIVARIATE Procedure
Variable: Depth_Range
| Moments | |||
|---|---|---|---|
| N | 12 | Sum Weights | 12 |
| Mean | 682 | Sum Observations | 8184 |
| Std Deviation | 569.811612 | Variance | 324685.273 |
| Skewness | 0.49949145 | Kurtosis | -0.666479 |
| Uncorrected SS | 9153026 | Corrected SS | 3571538 |
| Coeff Variation | 83.5500897 | Std Error Mean | 164.490444 |
| Basic Statistical Measures | |||
|---|---|---|---|
| Location | Variability | ||
| Mean | 682.000 | Std Deviation | 569.81161 |
| Median | 650.000 | Variance | 324685 |
| Mode | 1000.000 | Range | 1760 |
| Interquartile Range | 952.50000 | ||
Note: The mode displayed is the smallest of 2 modes with a count of 2.
| Tests for Location: Mu0=0 | ||||
|---|---|---|---|---|
| Test | Statistic | p Value | ||
| Student's t | t | 4.146138 | Pr > |t| | 0.0016 |
| Sign | M | 6 | Pr >= |M| | 0.0005 |
| Signed Rank | S | 39 | Pr >= |S| | 0.0005 |
| Quantiles (Definition 5) | |
|---|---|
| Level | Quantile |
| 100% Max | 1800.0 |
| 99% | 1800.0 |
| 95% | 1800.0 |
| 90% | 1200.0 |
| 75% Q3 | 1100.0 |
| 50% Median | 650.0 |
| 25% Q1 | 147.5 |
| 10% | 49.0 |
| 5% | 40.0 |
| 1% | 40.0 |
| 0% Min | 40.0 |
| Extreme Observations | |||
|---|---|---|---|
| Lowest | Highest | ||
| Value | Obs | Value | Obs |
| 40 | 12 | 1000 | 5 |
| 49 | 3 | 1000 | 6 |
| 95 | 10 | 1200 | 2 |
| 200 | 8 | 1200 | 9 |
| 300 | 11 | 1800 | 4 |
The UNIVARIATE Procedure
The UNIVARIATE Procedure
Variable: Years_Monitored (Years Between First Record and Last Survey)
| Moments | |||
|---|---|---|---|
| N | 12 | Sum Weights | 12 |
| Mean | 51.6666667 | Sum Observations | 620 |
| Std Deviation | 15.9848413 | Variance | 255.515152 |
| Skewness | 0.02401469 | Kurtosis | -1.4730386 |
| Uncorrected SS | 34844 | Corrected SS | 2810.66667 |
| Coeff Variation | 30.9384025 | Std Error Mean | 4.61442621 |
| Basic Statistical Measures | |||
|---|---|---|---|
| Location | Variability | ||
| Mean | 51.66667 | Std Deviation | 15.98484 |
| Median | 51.00000 | Variance | 255.51515 |
| Mode | . | Range | 46.00000 |
| Interquartile Range | 29.00000 | ||
| Tests for Location: Mu0=0 | ||||
|---|---|---|---|---|
| Test | Statistic | p Value | ||
| Student's t | t | 11.19677 | Pr > |t| | <.0001 |
| Sign | M | 6 | Pr >= |M| | 0.0005 |
| Signed Rank | S | 39 | Pr >= |S| | 0.0005 |
| Quantiles (Definition 5) | |
|---|---|
| Level | Quantile |
| 100% Max | 74.0 |
| 99% | 74.0 |
| 95% | 74.0 |
| 90% | 72.0 |
| 75% Q3 | 66.5 |
| 50% Median | 51.0 |
| 25% Q1 | 37.5 |
| 10% | 33.0 |
| 5% | 28.0 |
| 1% | 28.0 |
| 0% Min | 28.0 |
| Extreme Observations | |||
|---|---|---|---|
| Lowest | Highest | ||
| Value | Obs | Value | Obs |
| 28 | 9 | 59 | 7 |
| 33 | 4 | 64 | 1 |
| 36 | 10 | 69 | 8 |
| 39 | 3 | 72 | 11 |
| 44 | 6 | 74 | 5 |
6. Categorical Patterns with PROC FREQ
proc freq data=marine_life_final;
tables Diet_Type*Extinction_Risk / norow nocol nopercent;
tables Ocean*Extinction_Risk / chisq;
run;
OUTPUT:
The FREQ Procedure
|
| ||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Statistics for Table of Ocean by Extinction_Risk
| Statistic | DF | Value | Prob |
|---|---|---|---|
| WARNING: 100% of the cells have expected counts less than 5. Chi-Square may not be a valid test. | |||
| Chi-Square | 12 | 9.2000 | 0.6858 |
| Likelihood Ratio Chi-Square | 12 | 10.9519 | 0.5330 |
| Mantel-Haenszel Chi-Square | 1 | 1.4323 | 0.2314 |
| Phi Coefficient | 0.8756 | ||
| Contingency Coefficient | 0.6588 | ||
| Cramer's V | 0.5055 | ||
Sample Size = 12
7. Data Exploration with PROC SQL
7.1 Identify deep-dwelling species (Max_Depth >= 1000 m)
proc sql;
create table deep_species as
select Species,Ocean,Lifespan,Extinction_Risk,Min_Depth,Max_Depth,Depth_Range,
Years_Monitored
from marine_life_final
where Max_Depth >= 1000
order by Max_Depth desc;
quit;
proc print data=deep_species;
run;
OUTPUT:
| Obs | Species | Ocean | Lifespan | Extinction_Risk | Min_Depth | Max_Depth | Depth_Range | Years_Monitored |
|---|---|---|---|---|---|---|---|---|
| 1 | Giant_Squid | Atlantic | 5 | Vulnerable | 200 | 2000 | 1800 | 33 |
| 2 | Anglerfish | Atlantic | 20 | Near Threatened | 300 | 1500 | 1200 | 28 |
| 3 | Great_White_Shark | Atlantic | 70 | Endangered | 0 | 1200 | 1200 | 48 |
| 4 | Leatherback_Turtle | Indian | 60 | Endangered | 0 | 1000 | 1000 | 74 |
| 5 | Manta_Ray | Pacific | 30 | Vulnerable | 0 | 1000 | 1000 | 44 |
7.2 Summary by Ocean: average lifespan and risk score
proc sql;
select Ocean,
count(*) as Num_Species,
mean(Lifespan) as Avg_Lifespan format=8.1,
mean(Risk_Score) as Avg_Risk_Score format=8.2,
mean(Years_Monitored) as Avg_Years_Monitored format=8.1
from marine_life_final
group by Ocean;
quit;
OUTPUT:
| Ocean | Num_Species | Avg_Lifespan | Avg_Risk_Score | Avg_Years_Monitored |
|---|---|---|---|---|
| Arctic | 1 | 50.0 | 3.20 | 59.0 |
| Atlantic | 4 | 41.3 | 2.85 | 44.5 |
| Indian | 2 | 37.5 | 3.30 | 55.0 |
| Pacific | 4 | 33.8 | 3.15 | 50.3 |
| Southern | 1 | 90.0 | 3.60 | 72.0 |
8. Visualization with PROC SGPLOT
proc sgplot data=marine_life_final;
scatter x=Depth_Range
y=Lifespan
/ group=Extinction_Risk
datalabel=Species;
xaxis label="Depth Range (m)";
yaxis label="Lifespan (years)";
title "Lifespan vs Depth Range by Extinction Risk for Marine Species";
run;
OUTPUT:
9. Extra Macro for Date-Based Risk Monitoring Group
%macro flag_longterm(ds=marine_life_final, out=marine_life_flagged, years=40);
data &out.;
set &ds.;
length Monitoring_Group $20;
if Years_Monitored >= &years then Monitoring_Group = "Long-term";
else Monitoring_Group = "Recent";
run;
proc print data=&out.;
run;
%mend flag_longterm;
%flag_longterm(years=35);
OUTPUT:
| Obs | Species | Ocean | Diet_Type | First_Recorded | Protection_Start | Last_Survey_Date | Min_Depth | Max_Depth | Lifespan | Risk_Score | Depth_Range | Extinction_Risk | Years_Monitored | Years_Protected | Next_Survey_Date | First_Year_Recorded | Last_Survey_Year | Last_Survey_Month | Last_Survey_Season | Monitoring_Group |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Blue_Whale | Pacific | Filter_Feeder | 01JAN1960 | 01JAN1986 | 15JUL2024 | 0 | 500 | 80 | 4.5 | 500 | Critically Endangered | 64 | 39 | 15JUL2025 | 1960 | 2024 | 7 | Summer | Long-term |
| 2 | Great_White_Shark | Atlantic | Carnivore | 01JAN1975 | 01JAN1991 | 20AUG2023 | 0 | 1200 | 70 | 3.8 | 1200 | Endangered | 48 | 34 | 20AUG2024 | 1975 | 2023 | 8 | Summer | Long-term |
| 3 | Clownfish | Pacific | Omnivore | 01JAN1985 | 01JAN2005 | 10JUN2024 | 1 | 50 | 10 | 1.8 | 49 | Near Threatened | 39 | 20 | 10JUN2025 | 1985 | 2024 | 6 | Summer | Long-term |
| 4 | Giant_Squid | Atlantic | Carnivore | 01JAN1990 | 01JAN2008 | 05MAY2023 | 200 | 2000 | 5 | 2.6 | 1800 | Vulnerable | 33 | 17 | 05MAY2024 | 1990 | 2023 | 5 | Spring | Recent |
| 5 | Leatherback_Turtle | Indian | Omnivore | 01JAN1950 | 01JAN1975 | 30SEP2024 | 0 | 1000 | 60 | 4.2 | 1000 | Endangered | 74 | 50 | 30SEP2025 | 1950 | 2024 | 9 | Autumn | Long-term |
| 6 | Manta_Ray | Pacific | Filter_Feeder | 01JAN1980 | 01JAN2000 | 01APR2024 | 0 | 1000 | 30 | 2.9 | 1000 | Vulnerable | 44 | 25 | 01APR2025 | 1980 | 2024 | 4 | Spring | Long-term |
| 7 | Orca | Arctic | Carnivore | 01JAN1965 | 01JAN1985 | 11NOV2024 | 0 | 800 | 50 | 3.2 | 800 | Vulnerable | 59 | 40 | 11NOV2025 | 1965 | 2024 | 11 | Autumn | Long-term |
| 8 | Green_Sea_Turtle | Atlantic | Herbivore | 01JAN1955 | 01JAN1970 | 18MAR2024 | 0 | 200 | 70 | 3.0 | 200 | Vulnerable | 69 | 55 | 18MAR2025 | 1955 | 2024 | 3 | Spring | Long-term |
| 9 | Anglerfish | Atlantic | Carnivore | 01JAN1995 | 01JAN2010 | 25DEC2023 | 300 | 1500 | 20 | 2.0 | 1200 | Near Threatened | 28 | 15 | 25DEC2024 | 1995 | 2023 | 12 | Winter | Recent |
| 10 | Coral_Grouper | Indian | Carnivore | 01JAN1988 | 01JAN2002 | 05JAN2024 | 5 | 100 | 15 | 2.4 | 95 | Near Threatened | 36 | 23 | 05JAN2025 | 1988 | 2024 | 1 | Winter | Long-term |
| 11 | Humpback_Whale | Southern | Filter_Feeder | 01JAN1952 | 01JAN1980 | 08SEP2024 | 0 | 300 | 90 | 3.6 | 300 | Endangered | 72 | 45 | 08SEP2025 | 1952 | 2024 | 9 | Autumn | Long-term |
| 12 | Sea_Otter | Pacific | Carnivore | 01JAN1970 | 01JAN1995 | 14FEB2024 | 0 | 40 | 15 | 3.4 | 40 | Vulnerable | 54 | 30 | 14FEB2025 | 1970 | 2024 | 2 | Winter | Long-term |
/* Quick frequency of monitoring group vs extinction risk */
proc freq data=marine_life_flagged;
tables Monitoring_Group*Extinction_Risk;
run;
The FREQ Procedure
|
| ||||||||||||||||||||||||||||||||||||
No comments:
Post a Comment