/*REWRITE COMMENTS FOR AN OUTSIDE AUDIENCE*/
proc import datafile='S:\Biogeochemistry\GCREW\Archived Data\2-CO2xN\2-SC Census Data\CO2xN Master SC Census 2005-2014 (08-25-2015).xlsx'
out=SCcensus
dbms=excel
replace;
sheet="Data";
run;
/*The code in this section uses the allometric equations developed by Jon Bakker to calculate the biomass of each stem measured.*/
data biomass; set SCcensus;
if Total_Height=-99 then Total_Height=.; /*take out missing values*/
if Width=-99 then Width=.;
if In_Out=0 then delete; /*Q7 and Q8 (In_Out=0) are outside controls, therefore we only calculate the biomass inside the chamber*/
biomass=-0.04027+(0.00005033*(total_height**2))+(0.01563*Width**2)+(0.0000008535*(Total_Height**2)*Width**2); /*From Jon Bakker's equation (Total_Height and Width)*/
proc sort; by Year Chamber CO2 Nitrogen Treatment Quadrat;
proc means noprint; var biomass; by Year Chamber CO2 Nitrogen Treatment Quadrat; output out=meanbiomass (drop = _type_ _freq_) mean=meanplantbio;
run;
/* This import step reads the census file with the stems count for each quadrat (2005-2014). Stem count (or density) is needed to convert the mass of individual stems
in the step above to total chamber biomass*/
data Density;
proc import datafile='S:\Biogeochemistry\GCREW\Archived Data\2-CO2xN\2-SC Census Data\CO2xN Master SC Density 2005-2014 (08-25-2015).xlsx'
out=SCdensity
dbms=excel
replace;
sheet="Data";
run;
data Density; set SCdensity;
if In_Out=0 then delete;
proc sort; by Year Chamber CO2 Nitrogen Treatment Quadrat;
run;
Data MergeData; merge meanbiomass Density; by Year Chamber CO2 Nitrogen Treatment Quadrat;
SCbiomass_m2=meanplantbio*stem_count/Quadrat_Area; /*Convert the total per quadrat to meter square by dividing by the area of the quadrat (0.09 m2).*/
SCdensity_m2=stem_count/Quadrat_Area; /*Convert the total number of stems per quadrat to meter square by dividing by the area of the quadrat.*/
run;
/*This means statement was the only way we could find to drop variables from MergeData without causing an explained error when opening
the output Excel file*/
proc means noprint; var SCbiomass_m2 SCdensity_m2;
by Year Chamber CO2 Nitrogen Treatment;
output out=SCshoots (drop = _type_ _freq_)
mean=SCbiomass_m2 SCdensity_m2;
run;
proc export data=SCshoots
outfile='S:\Biogeochemistry\GCREW\Archived Data\2-CO2xN\1-Biomass (Derived)\1-CO2xN Sedge Shoot Biomass 2005-2014' replace dbms=excel;
run;