p4com_main_03.21.11.txt

Author: Abt Associates Inc.

Created: 1/31/2008

Updated: 3/22/2011

Purpose: This is a SAS program which calculates commercial fishing benefits

associated with the proposed 316(b) existing facilities regulation;

*!! Benefits are reported in $1,000.

*The location of the input and output files is here;

%let d=h; *(C or H drive);

%let mainloc=&d.:\ERD\TYCHE Contract\Assignments\WA 2-15 (316b Benefits & SP

Study)\Task 5 - Benefits Analytic Support\IE_032111\Com\;

%let inloc=&mainloc.Inputs\;

%let outloc=&mainloc.Outputs\;

%let ie_year_1=2017; *(define maximum year to be included in the IM only

tech, early compliance year run);

%let ie_year_2=2018; *(define mininum year to be included in CT tech run);

libname outloc "&outloc";

*The name of the input file is;

%let input=Com_Inputs_03.21.11.xls;

%let input2=IE_outputs_22MAR11.xls;

*rec_bottomline.sas7bdat;

*The name of the output files are;

%let output=P2.08 ComBenOutputs_&sysdate..xls;

%let tables=P2.08 ComBenTables_&sysdate..xls;

%let SumTables=P2.08 ComBenTablesSum_&sysdate..xls;

*%let printout=&outloc.Com Ben Tables &sysdate..rtf;

%let printout3=&outloc.Com Ben Tables &sysdate..csv;

*assumptions;

%let t0=2012; *(define when time zero is);

%let yrsc=50; *(define number of compliance years);

%let Elast_saltwater=-1.89;

%let Elast_shrimp=-.63;

%let Elast_crabs=-1.31;

%let ieunits=1;

%let firsttable=8;

%let capdefinition=reduction;

%macro cyr;

cydata.tmn1 as cyr_base,

cydata.tmn1 as cyr_tmn1,

cydata.tmn2 as cyr_tmn2,

cydata.tmn3 as cyr_tmn3,

cydata.tmn4 as cyr_tmn4

%mend;

*select option controls below;

%macro optionmac0(var);

if &var=1 then do;

*define abbreviated option names;

if option_name="option.tmn1" then

option="tmn1";

else if option_name="option.tmn2" then

option="tmn2";

else if option_name="option.tmn3"

then option="tmn3";

else if option_name="option.tmn4"

then option="tmn4";

end;

if &var=2 then do;

Page 1
p4com_main_03.21.11.txt

*SELECT baseline option;

if option_name ="option.tmn1";

end;

%mend;

%macro optionmac00;

%step5schedule(baseline,cyr_base);

%step5schedule(tmn1x,cyr_tmn1);

%step5schedule(tmn2x,cyr_tmn2);

%step5schedule(tmn3x,cyr_tmn3);

%step5schedule(tmn4x,cyr_tmn4);

data Step5idata;

length option $50.0;

set s8i_baseline s8i_baseline_0 s8i_tmn1x s8i_tmn1x_0 s8i_tmn2x

s8i_tmn2x_0 s8i_tmn3x s8i_tmn3x_0 s8i_tmn4x s8i_tmn4x_0

;

run;

%mend;

%macro optionmac11;

%step6schedule(baseline,cyr_base);

%step6schedule(tmn1x,cyr_tmn1);

%step6schedule(tmn2x,cyr_tmn2);

%step6schedule(tmn3x,cyr_tmn3);

%step6schedule(tmn4x,cyr_tmn4);

data Step5tdata;

length option $50.0;

set s8t_baseline s8t_baseline_0 s8t_tmn1x s8t_tmn1x_0 s8t_tmn2x

s8t_tmn2x_0 s8t_tmn3x s8t_tmn3x_0 s8t_tmn4x s8t_tmn4x_0

;

run;

%mend;

*select benfits schedule (st5) and IE data option (st4);

%macro optionmac1;

case

when st5.option="baseline" and

st4.option="baseline" then "baseline"

when st5.option="baseline_0" and

st4.option="baseline" then "baseline_0"

when st5.option="tmn1x" and

st4.option="tmn1" then "tmn1"

when st5.option="tmn1x_0" and

st4.option="tmn1" then "tmn1_0"

when st5.option="tmn2x" and

st4.option="tmn2" then "tmn2"

when st5.option="tmn2x_0" and

st4.option="tmn2" then "tmn2_0"

when st5.option="tmn3x" and

st4.option="tmn3" then "tmn3"

when st5.option="tmn3x_0" and

st4.option="tmn3" then "tmn3_0"

when st5.option="tmn4x" and

st4.option="tmn4" then "tmn4"

when st5.option="tmn4x_0" and

st4.option="tmn4" then "tmn4_0"

else "delete"

Page 2
p4com_main_03.21.11.txt

end as optionname

%mend;

%macro optionmac2; *select option, IE variabble, IE variable percentage factor;

%undiscsurplus(baseline,reduction,rpercent);

%undiscsurplus(tmn1,reduction,rpercent);

%undiscsurplus(tmn2,reduction,rpercent);

%undiscsurplus(tmn3,reduction,rpercent);

%undiscsurplus(tmn4,reduction,rpercent);

%mend;

%macro optionmac2a; *select option, IE variable, IE variable percentage factor;

if optionname in("baseline","tmn1","tmn2","tmn3","tmn4");

if optionname="baseline" then sortx=1;

else if optionname="tmn1" then sortx=2;

else if optionname="tmn2" then sortx=3;

else if optionname="tmn3" then sortx=4;

else if optionname="tmn4" then sortx=5;

%mend;

%macro optionmac3; *perform macro for each option for which a regional table is

presented;

/*%summarybyoption(baseline,NE1,NE1); */

/*%summarybyoption(baseline,NE2,NE2); */

%summarybyoption(baseline_0,tmn1_0,tmn1_0);

/*%summarybyoption(baseline,MN4,MN4); */

%summarybyoption(baseline_0,tmn2_0,tmn2_0);

%summarybyoption(baseline_0,tmn3_0,tmn3_0);

%summarybyoption(baseline_0,tmn4_0,tmn4_0);

%mend;

%macro optionmac4;

if option="baseline" then do; sort1=1;

option="baseline"; end;

else if option="tmn1" then do; sort1=2;

option="tmn1"; end;

else if option="tmn2" then do; sort1=3; option="tmn2";

end;

else if option="tmn3" then do; sort1=4;

option="tmn3"; end;

else if option="tmn4" then do; sort1=5;

option="tmn4"; end;

%mend optionmac4;

%let speciesoptions=baseline^tmn1^tmn2^tmn3^tmn4;

%let titleoptions=baseline^tmn1^tmn2^tmn3^tmn4;

%let regionoptions=tmn1_0^tmn2_0^tmn3_0^tmn4_0;

%let speciesnum=5; * (all options incl. baseline) select number of

species-tables per region (number in speciesoptions list above);

%let rnum=4; * (all options minus baseline) select number of

region-summary-tables per region (number in regionoptions list above);

%let nby=9; * (sum of two above) select number of tables for

each region , sum of speciesnum and rnum;

%let natoptions=baseline_0^tmn1_0^tmn2_0^tmn3_0^tmn4_0;*list options presented in

national tables;

%let natnum=5; *number of national tables in natoptions list;

*list regional table titles;

%let TableTitles=

Page 3
p4com_main_03.21.11.txt

baseline^tmn1^tmn2^tmn3^tmn4;

*list national table titles;

%let nattitles=

Baseline Elimination (w/o Consumer Surplus)

tmn1^tmn2^tmn3^tmn4;

*This is a macro that can be used to import data from excel;

%macro import(infile,insheet,out);

PROC IMPORT OUT= WORK.&out

DATAFILE= "&infile"

DBMS=EXCEL REPLACE;

SHEET="&insheet.$";

GETNAMES=YES;

MIXED=NO;

SCANTEXT=YES;

USEDATE=YES;

SCANTIME=YES;

RUN;

%mend;

*This is a macro that can be used to export data to excel;

%macro export(datafile,outfile,sheet);

PROC EXPORT DATA= &datafile

OUTFILE= &outfile

DBMS=EXCEL replace;

SHEET=&sheet;

RUN;

%mend;

* 1 Get data on Business as Usual (BAU) scenario for gross revenues and

prices

Region/Species-Specific Prices and Quantities are assumed;

* 1a import landings data;

%import(&inloc.&input,Landings_all,p1);

* 1b drop subtotal rows, define region variable;

data p2 dropped;

set p1;

if year~=.;

*define the north atlantic region;

if

state="Massachusetts" |

state="Connecticut" |

state="Rhode Island" |

state="New Hampshire" |

state="Maine"

then Region="NA";

*define the mid-atlantic region;

else if

state="New York" |

state="New Jersey" |

state="Maryland" |

state="Delaware" |

state="Virginia"

then Region="MA";

*define the california region;

else if state="California"

then Region="CA";

*define the gulf of mexico region;

else if state="Florida West Coast" |

state="Alabama" |

state="Mississippi" |

state="Louisiana" |

Page 4
p4com_main_03.21.11.txt

state="Texas"

then region="GM";

*define the great lakes region;

else if state="Michigan" |

state="Ohio" |

state="Minnesota" |

state="Wisconsin"

then region="GL";

*define the south atlantic region;

else if state="North Carolina" |

state="South Carolina" |

state="Georgia" |

state="Florida East Coast"

then region="SA";

else output dropped; *the data set, dropped, contains data from

states not considered;

if region~=" " then output p2; *here we output the landings and

price data that we will use;

run;

* 1c import cpi data to adjust prices to 2008$;

%import(&inloc.&input,CPI.2002.2009,cpi);

* 1d join cpi data and landings data, adjust prices to 2008$;

proc sql;

create table p3 as select

p2.region,

p2.state,

p2.year,

p2.species as AFSSpecies, /*species as defined in landings data*/

p2.pounds,

p2.dollars,

cpi.oneis2009,

p2.dollars*cpi.oneis2009 as adjusteddollars /*here prices are

adjusted to 2008$*/

from p2 as p2 left join cpi on

p2.year=cpi.year;

quit;

* 1e import mapping of various species definitions;

%import(&inloc.&input,SpeciesValueMap,smap);

* 1f join species map with landings data

(the landings data species definitions are mapped to the I&E

species definitions);

proc sql;

create table p4 as select

s.*,

p.*

from smap as s left join p3 as p

on s.valspecies=p.AFSSpecies;

quit;

* 1g drop species that are double counted;

proc sort data=p4 out=p5; by year region state AFSSpecies; run;

data p6 temp;

set p5;

by year region state AFSSpecies;

if first.AFSSpecies then output p6; *keep one of each species type;

else output temp; *output double-couted species;

run;

* 1h generate dataset of pounds of harvest, BAU gross revenues,

Page 5
p4com_main_03.21.11.txt

and BAU prices, by region and species;

proc sql;

create table p7 as select

region label="Region Abbreviation",

cfspecies label="Commercial Fishing Species Market Group",

sum(pounds)/5 as pounds format=comma30.0 label="average annual lbs",

sum(adjusteddollars)/5 as dollars2008 format=dollar30.0

label="average annual 2009$",

sum(adjusteddollars)/sum(pounds) as price2008 format=dollar30.2

label="average dockside price 2009$"

from p6 where afsspecies~=" " group by region,cfspecies;

quit;

* 1i generate dataset of pounds of harvest, BAU gross revenues,

and BAU prices, by region for Species without Specific data:

cfspecies = "blank";

proc sql;

create table p8 as select

region label="Region Abbreviation",

"blank" as cfspecies format=$50. label="Commercial Fishing Species

Market Group",

sum(pounds)/5 as pounds format=comma30.0 label="average annual lbs",

sum(adjusteddollars)/5 as dollars2008 format=dollar30.0

label="average annual 2009$",

sum(adjusteddollars)/sum(pounds) as price2008 format=dollar30.2

label="average dockside price 2009$"

from p6 where afsspecies~=" " group by region;

quit;

* 1j generate final dataset of pounds of harvest, BAU gross

revenues,

and BAU prices, by region and species;

data step1data;

set p7 p8;

run;

* 2 Get NB Ratio data and join it with the revnenue/price data;

*The NB ratio is the ratio by which the change in gross

revenue can be multiplied to

obtain the change in producer surplus;

* 2a Import data;

%import(&inloc.&input,NBRatio,r1);

* 2b drop unneeded vars;

data r2 (keep=region species_econ ABT_NB_Ratio);

set r1;

if lossmode~='imp&ent'; *we dont need data for I&E combined;

if species_econ="other.com" then species_econ="other.com.species";

if species_econ="dungeness" then species_econ="dungeness.crab";

run;

* 2c change 'other' species to a consistent name;

proc sort data=r2 out=r2a; by region species_econ ABT_NB_Ratio; run;

data r2b;

set r2a;

by region species_econ ABT_NB_Ratio;

if region="calif" and species_econ="non.ris.com" and

first.species_econ then species_econ="other.com.species";

if region="northatlantic" and species_econ="non.ris.com" and

first.species_econ then species_econ="other.com.species";

Page 6
p4com_main_03.21.11.txt

if region="southatlantic" and species_econ="non.ris.com" and

first.species_econ then species_econ="other.com.species";

if region="gulfmexico" and species_econ="non.ris.com" and

first.species_econ then species_econ="other.com.species";

run;

* 2d sort data and drop duplicate observations;

proc sort data=r2b out=r3; by region species_econ ABT_NB_Ratio; run;

data r4 error1; *in this data step, we want to keep only unique species-NBRatio

observations;

set r3;

by region species_econ ABT_NB_Ratio;

if first.ABT_NB_Ratio then rat=1;

if first.species_econ then spe=1;

if first.region then reg=1;

*(A) drop duplicate obervations;

if rat=1 and spe~=1 and species_econ="anchovies" and

region="calif" then delete;

*(B) Look for duplicate obervations that need to be dropped;

else if rat=1 and spe~=1 then do;

put "r4 data setp error caused by region:" region

"and species: " species_econ;

output error1;

end;

if rat=1 and spe=1 then output r4;

else if rat=1 | spe=1 then output error1;

run;

* 2e drop extra variables;

data r5 (keep=re region species_econ ABT_NB_Ratio);

set r4;

length re $3.;

*recode the region variable;

if region="calif" then re="CA";

else if region="greatlakes" then re="GL";

else if region="gulfmexico" then re="GM";

else if region="midatlantic" then re="MA";

else if region="northatlantic" then re="NA";

else if region="southatlantic" then re="SA";

else put "data step generating r5 has an error";

label re="Region Abbreviation"

region="region (short)"

species_econ="I&E Species Name"

ABT_NB_Ratio="Net Benefits Ratio";

run;

* 2f get map between "I&E species" and "Commercial Fishery

Species";

proc sort data=smap out=smap2; by cfspecies iespecies; run;

data smap3;

set smap2;

by cfspecies iespecies;

if first.iespecies;

run;

* 2g Add "Commercial Fishery Species" variable to NB Ratio data;

proc sql;

create table r6 as select

r5.re,

r5.region,

smap3.cfspecies label="Commercial Fishing Species Market Group",

r5.species_econ,

Page 7
p4com_main_03.21.11.txt

r5.ABT_NB_Ratio

from r5 left join smap3 on

r5.species_econ=smap3.iespecies

order by re,cfspecies,species_econ;

quit;

* 2h drop observations without "Commercial Fishery Species" ;

data step2data;

set r6;

if cfspecies~=" ";

*Use generic price for GL sculpins because landings data are not

available;

if re="GL" and species_econ="sculpins" then cfspecies="blank";

run;

* 3 Combine Price and Ratio Data;

* 3a Combine Price and Ratio Data;

proc sql;

create table D1 as select

st2.*,st1.pounds,st1.price2008,st1.dollars2008

from step2data as st2 left join step1data as st1 on

st1.cfspecies=st2.cfspecies

and st1.region=st2.re

order by st2.region,st2.species_econ;

quit;

* 3b Perform Data Check;

data PriceIsMissing;

set d1;

if price2008=.;

put "Error in PriceIsMissing datasetp for species = "

species_econ

" No Landings data for these species, in the region:

" region;

run;

* 3c Use Average Price Data where species specific price is not

available;

data Step3data;* (drop=Aprice2008);

* if _n_=1 then set Allspeciesprice (keep=Aprice2008);

set D1;

* if price2008=. then price2008=Aprice2008;

run;

* 4 Get I&E Data;

* 4a Import I&E Data;

%import(&inloc.&input2,BNB_IMP,I);

%import(&inloc.&input2,BNB_ENT,E);

%import(&inloc.&input2,BNB_IE,ei);

%import(&inloc.&input2,REDUCTIONS_DETAIL,reductions_detail)

************************************************************************************

*************;

%macro iore(lm);

data &lm.1 (keep=option option_name region species_econ lossmode com_loss);

length option $8.;

set &lm.;

if metric ="yf.lbs"

and comrec_type ="com.types"

and species_econ ~="zz.all.species"

and region ~="zz.allregions";

Page 8
p4com_main_03.21.11.txt

%optionmac0(1);

rename benefit_value_regional=com_loss;

run;

data &lm.2 (keep=option option_name region species_econ lossmode com_loss);

length region $20. option $8.;

set &lm.;

if metric ="yf.lbs"

and comrec_type ="com.types"

and species_econ ~="zz.all.species"

and region ~="zz.allregions";

%optionmac0(2);

option="baseline";

rename baseline_value_regional=com_loss;

run;

data &lm.3;

set &lm.2 &lm.1;

if species_econ="other.com" then species_econ="other.com.species";

run;

%mend;

%iore(i);

%iore(e);

%iore(ei);

data ie2 (drop=option_name);

set i3 e3;

if species_econ="dungeness" then species_econ="dungeness.crab";

if option ="." then delete;

run;

*%export(ie2,"&outloc.&output",ie2);

* 4c Add "Commercial Fishery Species" variable to I&E data;

proc sql;

create table ie3 as select

ie2.*,

smap3.cfspecies

from ie2 left join smap3 on

ie2.species_econ=smap3.iespecies;

quit;

* 4d Calculate total I&E eliminations and reductions by Option,

Region, and CFspecies;

proc sql;

create table ie4 as select

option,region,cfspecies,

sum(com_loss) as treduction

from ie3 group by option,region,cfspecies;

quit;

* 4e Calculate shares of total eliminations and reductions

by:

lossmode (impingment or entrainment)

and I&E Species (CFspecies may include more

than one I&E Species);

Page 9
p4com_main_03.21.11.txt

proc sql;

create table ie5 as select

ie4.option,ie4.region,

ie3.species_econ,

ie4.cfspecies,

ie3.lossmode,

ie3.com_loss/ie4.treduction as rpercent,

ie4.treduction

from ie4 left join ie3 on

ie3.option=ie4.option and

ie3.region=ie4.region and

ie3.cfspecies=ie4.cfspecies;

quit;

* 4f combine IE data with prices data;

proc sql;

create table Step4Data as select

ie5.option label="Regulatory Option",

st3.region,

st3.re,

st3.cfspecies,

st3.species_econ,

ie5.lossmode label="Type of Losses: impingement or entrainment",

ie5.rpercent format=percent15.2 label="LossMode/IE Species Share of

Reductions",

ie5.treduction*&ieunits. as reduction

format=comma20.0 Label="option/region/CFSpecies Reductions

(LBS)",

st3.ABT_NB_Ratio,

st3.pounds as oldlbs Label="BAU Average Annual LBS",

st3.price2008 Label="BAU Average Dockside Price 2009$",

st3.dollars2008 Label="BAU Gross Dockside Revenues 2009$"

from ie5 left join step3data as st3

on

ie5.region=st3.region and

ie5.species_econ=st3.species_econ

where ie5.rpercent>0 and ie5.region~="all.regions.combined"

and ie5.region~="inland"

and ie5.species_econ~="all.species.combined" and

ie5.species_econ~="other.rec.species"

order by

ie5.option,ie5.region,st3.cfspecies,st3.species_econ,ie5.lossmode;

quit;

/* 5 Calculate Benefits Schedule By Option;*/

* 5a Import facility data with both facility id's;

%import(&inloc.&input,IDMAP,f1);

* 5b Import data with weights;

%import(&inloc.&input,ID_AND_WEIGHT,ID_AND_WEIGHT);

* 5c Import data with region and flow;

%import(&inloc.&input,flowdata,f3);

* 5d Import data with compliance dates;

%import(&inloc.&input,complianceyear,cydata);

* 5e Get ID for joining datasets;

proc sql;

create table f4 as select

id.plntcode,

Page 10
p4com_main_03.21.11.txt

w.id as facility,

w.ps_wgt as Weighting_Factor

from f1 as id right join ID_AND_WEIGHT as w on id.surveyid=w.id;

quit;

* 5f Drop double counted plants;

proc sort data=f4 out=f5; by plntcode; run;

data f6;

set f5;

by plntcode;

if (not first.plntcode | not last.plntcode) and

Weighting_Factor=0 then delete;

run;

* 5f join flow and weight data;

proc sql;

create table f7 as select

f6.*,

f3.Benefits_Region,f3.AverageFlow

from f6 full join f3 on f6.plntcode=f3.EIA_Code where f3.EIA_Code~=.;

quit;

* 5g recode region variable;

data f8 (keep=region AverageFlow Weighting_Factor PLNTCODE facility);

set f7;

format region $14.;

if Benefits_Region="CN" | Benefits_Region="CS" |

Benefits_Region="CAL" | Benefits_Region="HI" then region="California";

else if Benefits_Region="GL"

then region="Great Lakes";

else if Benefits_Region="INL"

then region="Inland";

else if Benefits_Region="MA"

then region="Mid-Atlantic";

else if Benefits_Region="Mex"

then region="Gulf of Mexico";

else if Benefits_Region="NA"

then region="North Atlantic";

else if Benefits_Region="SA"

then region="South Atlantic";

else if Benefits_Region="PNW" then delete;

else if Benefits_Region="VI" then delete;

run;

* 5h combine and format data with average flow, region, wgt, and

compliance year;

proc sql;

create table s2a as select

f8.plntcode,f8.AverageFlow as avgflow,f8.Region,f8.Weighting_Factor

as newweight,

%cyr

from f8 full join cydata on cydata.id=f8.facility;

quit;

proc sql;

create table s2 as select

s2a.*

from s2a;

quit;

Data s2;

set s2;

Page 11
p4com_main_03.21.11.txt

if region="" then delete;

RUN;

Proc sort data=s2 out=s2;

by region;

RUN;

%import(&inloc.&input,schedule,schedule);

data schedule1;

set schedule;

drop f18 f19;

format reg $14.;

if Benefits_Region="CN" | Benefits_Region="CS" |

Benefits_Region="CAL" | Benefits_Region="HI" then reg="calif";

else if Benefits_Region="GL"

then reg="greatlakes";

else if Benefits_Region="INL"

then reg="inland";

else if Benefits_Region="MA"

then reg="midatlantic";

else if Benefits_Region="Mex"

then reg="gulfmexico";

else if Benefits_Region="NA"

then reg="northatlantic";

else if Benefits_Region="SA"

then reg="southatlantic";

array rbschd_{60}rbschd_1 - rbschd_60;

array benschd_(60) benschd_1 - benschd_60;

do i=1 to 60;

rbschd_(i) = benschd_(i);

end;

run;

proc sql;

create table s6 (drop=option reg) as select

%optionmac1 ,

st4.region,

st4.re,

st4.cfspecies,

st4.species_econ,

st4.lossmode,

st4.rpercent format=percent12.2,

st4.reduction format=comma20.0,

st4.ABT_NB_Ratio,

st4.oldlbs,

st4.price2008,

st4.dollars2008,

st5.*

from Step4data as st4 left join schedule1 (keep=option reg

rbschd_1-rbschd_60) as st5 on

st4.region=st5.reg

ORDER by

st5.option,st4.region,st4.cfspecies,st4.species_econ,st4.lossmode;

quit;

************************************************************************************

***************************

Page 12
p4com_main_03.21.11.txt

************************************************************************************

***************************

* 5j THIS MACRO CALCULATES BENEFITS SCHEDULE FOR FACILITIES ASSIGNED

IM TECH

Incorporates the biological lag and the lag in compliance;

%macro step5schedule(opt,cyr);

* 5j1 generate benefits schedule;

data s3i;

set s2;

where region~="Virgin Islands";

array flowy_(60) flowy_1-flowy_60;

array bio(60) bio_1-bio_60;

array bschd(60) bschd_1-bschd_60;

do i=1 to 60;

if "&opt"="baseline" then do;

flowy_(i)=avgflow;

if region="Inland" | region="Great

Lakes" | region="Gulf of Mexico" then do; *benefits begin in first year for these

regions;

if i=1 then bio(i)=.1;

if i=2 then bio(i)=.2;

if i=3 then bio(i)=.8;

if i=4 then bio(i)=.9;

if i=5 then bio(i)=.95;

if i=6 then bio(i)=1;

if i>6 and i<=45 then

bio(i)=1;

if i=46 then bio(i)=.9;

if i=47 then bio(i)=.8;

if i=48 then bio(i)=.2;

if i=49 then bio(i)=.1;

if i=50 then bio(i)=.05;

if i>50 then bio(i)=0;

end;

else do; *benefits begin a year

later for other regions (midatlantic, california, northatlantic, southatlantic);

if i=1 then bio(i)=0;

if i=2 then bio(i)=.1;

if i=3 then bio(i)=.2;

if i=4 then bio(i)=.8;

if i=5 then bio(i)=.9;

if i=6 then bio(i)=.95;

if i=7 then bio(i)=1;

if i>7 and i<=45 then

bio(i)=1;

if i=46 then bio(i)=.9;

if i=47 then bio(i)=.8;

if i=48 then bio(i)=.2;

if i=49 then bio(i)=.1;

if i=50 then bio(i)=.05;

if i>50 then bio(i)=0;

end;

end;

else do;

if &cyr.>&ie_year_1. then

delete;

if region="Inland" |

region="Great Lakes" | region="Gulf of Mexico" then do;

*benefits begin in

first year for these regions;

x=i-&cyr.+&t0.;

Page 13
p4com_main_03.21.11.txt

*e.g., if i=1 and cyr = 2011 and first year of rule is 2011 then x=1 in 2011;

if x<=0

then flowy_(i)=0; *x=1 in first year of compliance;

else

flowy_(i)=avgflow;

if _n_=1 then put

"Not BASELINE";

if x<=0

then bio(i)=0;

else if x=1 then

bio(i)=.02;

else if x=2 then

bio(i)=.06;

else if x=3 then

bio(i)=.22;

else if x=4 then

bio(i)=.4;

else if x=5 then

bio(i)=.59;

else if x=6 then

bio(i)=.77;

else if x=7 then

bio(i)=.93;

else if x=8 then

bio(i)=.97;

else if x=9 then

bio(i)=.99;

else if x>=9 and

i<=45 then bio(i)=1;

else if i=46 then

bio(i)=.9;

else if i=47 then

bio(i)=.8;

else if i=48 then

bio(i)=.2;

else if i=49 then

bio(i)=.1;

else if i=50 then

bio(i)=0.05;

else if i>50 then

bio(i)=0;

end;

else do;

*benefits begin in

second year for these regions;

x=i-&cyr.+&t0.;

*e.g., if i=1 and cyr = 2011 and first year of rule is 2011 then x=1 in 2012;

if x<0

then flowy_(i)=0;*x=1 in second year of compliance;

else

flowy_(i)=avgflow;

if _n_=1 then put

"Not BASELINE";

if x<=0

then bio(i)=0;

else if x=1 then

bio(i)=0;

else if x=2 then

bio(i)=.02;

else if x=3 then

Page 14
p4com_main_03.21.11.txt

bio(i)=.06;

else if x=4 then

bio(i)=.22;

else if x=5 then

bio(i)=.4;

else if x=6 then

bio(i)=.59;

else if x=7 then

bio(i)=.77;

else if x=8 then

bio(i)=.93;

else if x=9 then

bio(i)=.97;

else if x=10 then

bio(i)=.99;

else if x>=10 and

i<=45 then bio(i)=1;

else if i=46 then

bio(i)=.9;

else if i=47 then

bio(i)=.8;

else if i=48 then

bio(i)=.2;

else if i=49 then

bio(i)=.1;

else if i=50 then

bio(i)=0.05;

else if i>50 then

bio(i)=0;

end;

end;

bschd(i)=(flowy_(i)*bio(i));

end;

format reg $30.;

if region="California"

then reg="calif";

else if region="Great Lakes" then

reg="greatlakes";

else if region="Gulf of Mexico" then

reg="gulfmexico";

else if region="Inland"

then reg="inland";

else if region="Mid-Atlantic" then

reg="midatlantic";

else if region="North Atlantic" then

reg="northatlantic";

else if region="South Atlantic" then

reg="southatlantic";

run;

* 5j2 calculate total average flow by region;

proc sql;

create table s5i as select

s3i.*,

sum(avgflow*newweight) as totalavgflow /*group flag*/

from s3i group by region;

quit;

* 5j3 generate flow and benefits schedule variables (for each

facility) as percentages to total regional average flow;

data s6i (drop=bio_1-bio_60 flowy_1-flowy_60);

Page 15
p4com_main_03.21.11.txt

set s5i;

array flowy_(60) flowy_1-flowy_60;

array bschd(60) bschd_1-bschd_60;

do i=1 to 60;

if totalavgflow=0 then flowy_(i)=0;

else if totalavgflow~=0 then

flowy_(i)=newweight*flowy_(i)/totalavgflow;

if totalavgflow=0 then bschd(i)=0;

else if totalavgflow~=0 then

bschd(i)=newweight*bschd(i)/totalavgflow;

end;

run;

* 5j4 sort data by region;

proc sort data=s6i out=s7i; by region; run;

* 5j6 generate benefits schedule variable for region,

e.g., 1 = full benefits, .5 = 50% of full benefits;

data s8i_&opt (keep=option region reg rbschd_1-rbschd_60);

retain option region reg rbschd_1-rbschd_60;

set s7i;

by region;

option="&opt";

array bschd(60) bschd_1-bschd_60;

array rbschd(60) rbschd_1-rbschd_60;

do i=1 to 60;

if first.region then rbschd(i)=bschd(i);

else rbschd(i)+bschd(i);

end;

if last.region;

run;

* 5j7: repeat 5j6 (for alternative presentation of

options);

data s8i_&opt._0 (keep=option region reg rbschd_1-rbschd_60);

retain option region reg rbschd_1-rbschd_60;

set s7i;

by region;

option="&opt._0";

array bschd(60) bschd_1-bschd_60;

array rbschd(60) rbschd_1-rbschd_60;

do i=1 to 60;

if first.region then rbschd(i)=bschd(i);

else rbschd(i)+bschd(i);

end;

if last.region;

run;

%mend;

************************************************************************************

***************************

************************************************************************************

***************************

* 5j THIS MACRO CALCULATES BENEFITS SCHEDULE FOR FACILITIES ASSIGNED

TOWERS

Incorporates the biological lag and the lag in compliance;

%macro step6schedule(opt,cyr);

* 5j1 generate benefits schedule;

data s3t;

set s2;

where region~="Virgin Islands";

array flowy_(60) flowy_1-flowy_60;

array bio(60) bio_1-bio_60;

array bschd(60) bschd_1-bschd_60;

Page 16
p4com_main_03.21.11.txt

do i=1 to 60;

if "&opt"="baseline" then do;

flowy_(i)=avgflow;

if region="Inland" | region="Great

Lakes" | region="Gulf of Mexico" then do;*benefits begin in first year for these

regions;

if i=1 then bio(i)=.1;

if i=2 then bio(i)=.2;

if i=3 then bio(i)=.8;

if i=4 then bio(i)=.9;

if i=5 then bio(i)=.95;

if i=6 then bio(i)=1;

if i>6 and i<=45 then

bio(i)=1;

if i=46 then bio(i)=.9;

if i=47 then bio(i)=.8;

if i=48 then bio(i)=.2;

if i=49 then bio(i)=.1;

if i=50 then bio(i)=.05;

if i>50 then bio(i)=0;

end;

else do; *benefits begin a year

later for other regions (midatlantic, california, northatlantic, southatlantic);

if i=1 then bio(i)=0;

if i=2 then bio(i)=.1;

if i=3 then bio(i)=.2;

if i=4 then bio(i)=.8;

if i=5 then bio(i)=.9;

if i=6 then bio(i)=.95;

if i=7 then bio(i)=1;

if i>7 and i<=45 then

bio(i)=1;

if i=46 then bio(i)=.9;

if i=47 then bio(i)=.8;

if i=48 then bio(i)=.2;

if i=59 then bio(i)=.1;

if i=50 then bio(i)=.05;

if i>50 then bio(i)=0;

end;

end;

else do;

if &cyr.<&ie_year_2. then

delete;

if region="Inland" |

region="Great Lakes" | region="Gulf of Mexico" then do;

*benefits begin in

first year for these regions;

x=i-&cyr.+&t0.;

*e.g., if i=1 and cyr = 2011 and first year of rule is 2011 then x=1 in 2011;

if x<=0

then flowy_(i)=0; *x=1 in first year of compliance;

else

flowy_(i)=avgflow;

if _n_=1 then put

"Not BASELINE";

if

x<=0 then bio(i)=0;

else if x=1 then

bio(i)=.02;

else if x=2 then

Page 17
p4com_main_03.21.11.txt

bio(i)=.06;

else if x=3 then

bio(i)=.22;

else if x=4 then

bio(i)=.4;

else if x=5 then

bio(i)=.59;

else if x=6 then

bio(i)=.77;

else if x=7 then

bio(i)=.93;

else if x=8 then

bio(i)=.97;

else if x=9 then

bio(i)=.99;

else if x>=9 and

i<=45 then bio(i)=1;

else if i=46 then

bio(i)=.9;

else if i=47 then

bio(i)=.8;

else if i=48 then

bio(i)=.2;

else if i=49 then

bio(i)=.1;

else if i=50 then

bio(i)=0.05;

else if i>50 then

bio(i)=0;

end;

else do;

*benefits begin in

second year for these regions;

x=i-&cyr.+&t0.;

*e.g., if i=1 and cyr = 2011 and first year of rule is 2011 then x=1 in 2012;

if x<0

then flowy_(i)=0;*x=1 in second year of compliance;

else

flowy_(i)=avgflow;

if _n_=1 then put

"Not BASELINE";

if x<=0

then bio(i)=0;

else if x=1 then

bio(i)=0;

else if x=2 then

bio(i)=.02;

else if x=3 then

bio(i)=.06;

else if x=4 then

bio(i)=.22;

else if x=5 then

bio(i)=.4;

else if x=6 then

bio(i)=.59;

else if x=7 then

bio(i)=.77;

else if x=8 then

bio(i)=.93;

else if x=9 then

bio(i)=.97;

Page 18
p4com_main_03.21.11.txt

else if x=10 then

bio(i)=.99;

else if x>=10 and

i<=45 then bio(i)=1;

else if i=46 then

bio(i)=.9;

else if i=47 then

bio(i)=.8;

else if i=48 then

bio(i)=.2;

else if i=49 then

bio(i)=.1;

else if i=50 then

bio(i)=0.05;

else if i>50 then

bio(i)=0;

end;

end;

bschd(i)=(flowy_(i)*bio(i));

end;

format reg $30.;

if region="California"

then reg="calif";

else if region="Great Lakes" then

reg="greatlakes";

else if region="Gulf of Mexico" then

reg="gulfmexico";

else if region="Inland"

then reg="inland";

else if region="Mid-Atlantic" then

reg="midatlantic";

else if region="North Atlantic" then

reg="northatlantic";

else if region="South Atlantic" then

reg="southatlantic";

run;

* 5j2 calculate total average flow by region;

proc sql;

create table s5t as select

s3t.*,

sum(avgflow*newweight) as totalavgflow /*group flag*/

from s3t group by region;

quit;

* 5j3 generate flow and benefits schedule variables (for each

facility) as percentages to total regional average flow;

data s6t (drop=bio_1-bio_60 flowy_1-flowy_60);

set s5t;

array flowy_(60) flowy_1-flowy_60;

array bschd(60) bschd_1-bschd_60;

do i=1 to 60;

if totalavgflow=0 then flowy_(i)=0;

else if totalavgflow~=0 then

flowy_(i)=newweight*flowy_(i)/totalavgflow;

if totalavgflow=0 then bschd(i)=0;

else if totalavgflow~=0 then

bschd(i)=newweight*bschd(i)/totalavgflow;

end;

run;

* 5j4 sort data by region;

Page 19
p4com_main_03.21.11.txt

proc sort data=s6t out=s7t; by region; run;

* 5j6 generate benefits schedule variable for region,

e.g., 1 = full benefits, .5 = 50% of full benefits;

data s8t_&opt (keep=option region reg rbschd_1-rbschd_60);

retain option region reg rbschd_1-rbschd_60;

set s7t;

by region;

option="&opt";

array bschd(60) bschd_1-bschd_60;

array rbschd(60) rbschd_1-rbschd_60;

do i=1 to 60;

if first.region then rbschd(i)=bschd(i);

else rbschd(i)+bschd(i);

end;

if last.region;

run;

* 5j7: repeat 5j6 (for alternative presentation of

options);

data s8t_&opt._0 (keep=option region reg rbschd_1-rbschd_60);

retain option region reg rbschd_1-rbschd_60;

set s7t;

by region;

option="&opt._0";

array bschd(60) bschd_1-bschd_60;

array rbschd(60) rbschd_1-rbschd_60;

do i=1 to 60;

if first.region then rbschd(i)=bschd(i);

else rbschd(i)+bschd(i);

end;

if last.region;

run;

%mend;

* 5j This macro calculates benefits schedule, incorporating the biological lag

and the lag in compliance;

* 5k Generate dataset of Benefits Schedule By Option;

%optionmac00;

%optionmac11;

*********************************************************************************

*********************************************************************************

NEED TO MANIPULATE Step5data in order to implement impingement fraction;

*need to rename array functions in the Step5idata and Step5data;

Data step5idata;

SET step5idata;

array rbschd_(60) rbschd_1 - rbschd_60;

array rbschd_i_(60) rbschd_i_1 - rbschd_i_60;

do i=1 to 60;

rbschd_i_(i)=rbschd_(i);

IF rbschd_i_(i)="." then rbschd_i_(i)=0;

end;

drop rbschd_1-rbschd_60 i;

if region="" then delete;

RUN;

Data step5tdata;

SET step5tdata;

array rbschd_(60) rbschd_1 - rbschd_60;

array rbschd_t_(60) rbschd_t_1 - rbschd_t_60;

do i=1 to 60;

rbschd_t_(i)=rbschd_(i);

IF rbschd_t_(i)="." then rbschd_t_(i)=0;

end;

Page 20
p4com_main_03.21.11.txt

drop rbschd_1-rbschd_60 i;

if region="" then delete;

RUN;

PROC SORT data=step5idata out=step5idata;

by option region reg;

RUN;

PROC SORT data=step5tdata out=step5tdata;

by option region reg;

RUN;

Data step5data;

merge step5idata step5tdata;

by option region reg;

RUN;

****reorganize reductions_detail sheet;

Data reductions_detail_1;

set reductions_detail;

format option $20.;

impingement_fraction_imp = (1-ccr_fraction_imp);

if option_name="option.tmn1" then option="tmn1x";

if option_name="option.tmn2" then option="tmn2x";

if option_name="option.tmn3" then option="tmn3x";

if option_name="option.tmn4" then option="tmn4x";

option_name=option;

reg=region;

DROP ccr_fraction_imp option_name region benefit_value_regional_imp;

RUN;

Data reductions_detail_2;

set reductions_detail;

format option $20.;

impingement_fraction_imp = (1-ccr_fraction_imp);

if option_name="option.tmn1" then option="tmn1x_0";

if option_name="option.tmn2" then option="tmn2x_0";

if option_name="option.tmn3" then option="tmn3x_0";

if option_name="option.tmn4" then option="tmn4x_0";

option_name=option;

reg=region;

DROP ccr_fraction_imp option_name region;

RUN;

Data reductions_detail_3;

set reductions_detail_1 reductions_detail_2;

RUN;

Proc sort data=reductions_detail_3 out=reductions_detail_3;

by option reg;

RUN;

Data step5data_1;

merge step5data reductions_detail_3;

by option reg;

RUN;

Data step5data_1;

set step5data_1;

if impingement_fraction_imp="." then impingement_fraction_imp=1;

RUN;

Data step5data_2;

set step5data_1;

array rbschd_i_(60) rbschd_i_1 - rbschd_i_60;

array rbschd_t_(60) rbschd_t_1 - rbschd_t_60;

array rbschd_adj_(60) rbschd_adj_1 - rbschd_adj_60;

do i=1 to 60;

if rbschd_i_(i)= "." then rbschd_i_(i)=0;

if rbschd_t_(i)= "." then rbschd_t_(i)=0;

rbschd_adj_(i)=impingement_fraction_imp*rbschd_i_(i)+(1-impingement_fraction_imp)*rb

schd_t_(i);

Page 21
p4com_main_03.21.11.txt

END;

DROP rbschd_i_1-rbschd_i_60 impingement_fraction_imp i;

RUN;

Data step5data_2imp;

set step5data_2;

drop rbschd_t_1-rbschd_t_60;

lossmode="imp";

array rbschd_adj_(60) rbschd_adj_1-rbschd_adj_60;

array rbschd_(60) rbschd_1-rbschd_60;

do i=1 to 60;

rbschd_(i)=rbschd_adj_(i);

END;

Drop rbschd_adj_1-rbschd_adj_60 i;

if option="tmn1x" then option="tmn1";

if option="tmn2x" then option="tmn2";

if option="tmn3x" then option="tmn3";

if option="tmn4x" then option="tmn4";

if option="tmn1x_0" then option="tmn1_0";

if option="tmn2x_0" then option="tmn2_0";

if option="tmn3x_0" then option="tmn3_0";

if option="tmn4x_0" then option="tmn4_0";

RUN;

Data step5data_2ent;

set step5data_2;

drop rbschd_adj_1-rbschd_adj_60;

lossmode="ent";

array rbschd_t_(60) rbschd_t_1-rbschd_t_60;

array rbschd_(60) rbschd_1-rbschd_60;

do i=1 to 60;

rbschd_(i)=rbschd_t_(i);

END;

Drop rbschd_t_1-rbschd_t_60 i;

if option="tmn1x" then option="tmn1";

if option="tmn2x" then option="tmn2";

if option="tmn3x" then option="tmn3";

if option="tmn4x" then option="tmn4";

if option="tmn1x_0" then option="tmn1_0";

if option="tmn2x_0" then option="tmn2_0";

if option="tmn3x_0" then option="tmn3_0";

if option="tmn4x_0" then option="tmn4_0";

RUN;

Data step5data_3;

set step5data_2imp step5data_2ent;

optionname=option;

*if reg="calif" then region="California";

*if reg="greatlakes" then region="Great Lakes";

*if reg="gulfmexico" then region="Gulf of Mexico";

*if reg="inland" then region="Inland";

*if reg="midatlantic" then region="Mid-Atlantic";

*if reg="northatlantic" then region="North Atlantic";

region=reg;

RUN;

*****************************************************************

*****************************************************************

Make changes related to repowering schedule;

%import(&inloc.&input2,rep_adj,rep_adj);

%import(&inloc.&input,rpschd,rpschd);

Proc sort data=rep_adj out=rep_adj;

by option;

Page 22
p4com_main_03.21.11.txt

RUN;

Proc sort data=rpschd out=rpschd;

by option;

RUN;

Data repow;

merge rep_adj rpschd;

by option;

adj=1/rp_adj;

drop rp_adj;

RUN;

Data repow_1;

set repow;

array rpschd_(60) rpschd_1-rpschd_60;

array rpschd_adj_(60) rpschd_adj_1-rpschd_adj_60;

do i=1 to 60;

rpschd_adj_(i)=rpschd_(i)*(1-adj);

if rpschd_(i)=0 then rpschd_adj_(i)=0;

end;

drop rp_adj rpschd_1-rpschd_60 i;

if lossmode="ie" then delete;

if region="zz.allregions" then delete;

RUN;

Proc Sort data=repow_1 out=repow_1;

by option region lossmode;

RUN;

PROC SORT data=step5data_3 out=step5data_3;

by option region lossmode;

RUN;

Data step5data_4;

merge step5data_3 repow_1;

by option region lossmode;

RUN;

Data step5data_5;

set step5data_4;

array rbschd_(60) rbschd_1-rbschd_60;

array rpschd_adj_(60) rpschd_adj_1-rpschd_adj_60;

array com_schd_(60) com_schd_1-com_schd_60;

do i=1 to 60;

com_schd_(i) = adj*rbschd_(i) + rpschd_adj_(i);

rbschd_(i)=com_schd_(i);

END;

drop i adj com_schd_1-com_schd_60 rpschd_adj_1-rpschd_adj_60;

RUN;

********************************************************************

END OF REPOWERING CALCULATIONS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

********************************************************************;

*to be merged with step6data;

**********************************************************************************

*create separate step4data files for the different options;

Data step4data;

length option $20;

set step4data;

RUN;

Page 23
p4com_main_03.21.11.txt

Data step4data_1;

length option $20;

set step4data;

if option="baseline" then option="baseline_0";

if option="tmn1" then option="tmn1_0";

if option="tmn2" then option="tmn2_0";

if option="tmn3" then option="tmn3_0";

if option="tmn4" then option="tmn4_0";

RUN;

Data step4data_2;

set step4data step4data_1;

RUN;

Proc sort data=step4data_2 out=step4data_2;

by option region lossmode;

Data s6;

merge step4data_2 step5data_5;

by option region lossmode;

RUN;

* 6 Join Price, Quantiy, and Losses data With Benefits Schedule By Option;

*proc sql;

*create table s6 (drop=option reg) as select

%optionmac1 ,

st4.region,

st4.re,

st4.cfspecies,

st4.species_econ,

st4.lossmode,

st4.rpercent format=percent12.2,

st4.reduction format=comma20.0,

st4.ABT_NB_Ratio,

st4.oldlbs,

st4.price2008,

st4.dollars2008,

st5.*

from Step4data as st4 left join Step5data (keep=option reg

rbschd_1-rbschd_60) as st5 on

st4.region=st5.reg

ORDER by

st5.option,st4.region,st4.cfspecies,st4.species_econ,st4.lossmode;

*quit;*/

* 6a delete uneeded data;

*data s6a;

* set s6;

* if optionname~="delete";

*run;

* 6b sort data;

proc sort data=s6 out=step6data;

by optionname region re cfspecies species_econ lossmode

rpercent

reduction ABT_NB_Ratio oldlbs price2008 dollars2008;

run;

data step6data_1;

set step6data;

if species_econ="" then delete;

RUN;

****************************

Page 24
p4com_main_03.21.11.txt

REPLACE schedule within step6data with fraction adjusted schedule;

*Proc Sort data=step6data out=step6data;

* by optionname region lossmode;

*RUN;

*Data step6data_1;

* set step6data;

* drop rbschd_1-rbschd_60;

*RUN;

*Data step6data_2;

* merge step6data_1 step5data_3;

* by optionname region lossmode;

*RUN;

*proc sort data=step6data_2 out=step6data_2;

* by optionname region re cfspecies species_econ lossmode rpercent

* reduction ABT_NB_Ratio oldlbs price2008 dollars2008;

*RUN;

* 7 Calculate Consumer and Producer Surplus For Years 1-15,

total over 15 years, and annualized over 15 years;

* 7a Reshape data so from wide to long;

proc transpose data=step6data_1 out=long6;

by optionname region re cfspecies species_econ lossmode rpercent

reduction ABT_NB_Ratio oldlbs price2008 dollars2008;

run;

* 7b reformat long-shaped data;

* adjust based on capping rules;

data long7 (drop=_name_ col1 oldreduction) check1 (keep=region cfspecies);

set long6;

rbschd=col1;

year=input(substr(_name_,8,2),2.0);

oldreduction=reduction;

reduction=&capdefinition.;

If region = "calif" and species_econ = "cabezon" then reduction =

min(reduction, 10000000); * These are the difference between the cap and baseilne

harvest;

If region = "calif" and species_econ = "california.halibut" then reduction =

min(reduction, 10000000);

If region = "calif" and species_econ = "sculpins" then reduction =

min(reduction, 10000000);

If region = "northatlantic" and species_econ = "sculpins" then reduction =

min(reduction, 3978);

If region = "midatlantic" and species_econ = "spot" then reduction =

min(reduction, 1111434);

if oldreduction~=reduction then output check1;

output long7;

run;

data long7a;

set long7;

if cfspecies in ("com.crabs","dungeness.crab","blue.crab","stone.crab")

then elasticity=&Elast_crabs;

else if cfspecies in ("pink.shrimp","pink shrimp","com.shrimp")

then elasticity=&Elast_shrimp;

*else if region="greatlakes" | cfspecies="blank"

then elasticity=.;

else if region~="greatlakes" & cfspecies~="blank"

then elasticity=&Elast_saltwater;

Page 25
p4com_main_03.21.11.txt

run;

proc sql;

create table check2 as select

region,cfspecies,count(region) as count

from check1 group by region,cfspecies;

quit;

%export(check2,"&outloc.&output.",binding);

* 7c Calculate Consumer and Producer Surplus For Years 1-50;

data long8;

set long7a;

/*if cfspecies in

("com.crabs","dungeness.crab","blue.crab","stone.crab")

then elasticity=&Elast_crabs;

else if cfspecies in ("pink.shrimp","pink shrimp","com.shrimp")

then elasticity=&Elast_shrimp;

*else if region="greatlakes" | cfspecies="blank"

then elasticity=.;

else if region~="greatlakes" & cfspecies~="blank"

then elasticity=&Elast_saltwater;

/*

if re="CA" and species_econ="cabezon"

then negprice=1;

else if re="CA" and species_econ="rockfishes" then

negprice=1;

else if re="CA" and species_econ="sculpins" then

negprice=1;

else if re="GM" and species_econ="spot"

then negprice=1;

else if re="GM" and species_econ="stone.crab" then

negprice=1;

else if re="NA" and species_econ="sculpins" then

negprice=1;

else if re="SA" and species_econ="spot"

then negprice=1;

*/

%macro undiscsurplus(opt,ievar,iepercent);

if optionname="&opt" then do; *(dont perform

for irrelevent options);

/*FLAG Rule of Thumb*/*if

region~="greatlakes" and cfspecies~="blank" and negprice~=1 then do;*(saltwater

species with landings data have consumer surplus);

if 1=2 then do; /*FLAG Rule of

Thumb*/

if &ievar.~=. and &ievar.~=0

then do;

percent=&iepercent.;

*elimination or reduction;

IEchange=&ievar.;

*elimination or reduction;

lbs=&ievar.*rbschd+oldlbs; *post-I&E reduction harvest;

price=price2008*((lbs/oldlbs-1)/elasticity+1); *post-I&E reduction price;

CS=((price2008-price)*oldlbs+0.5*(price2008-price)*

(lbs-oldlbs))*&iepercent.; *post-I&E reduction Consumer surp;

GR=price*lbs-price2008*oldlbs; *post-I&E reduction Gross revenue (not adjusted for

imp/ent and species);

Page 26
p4com_main_03.21.11.txt

PS=GR*ABT_NB_Ratio*&iepercent.; *post-I&E reduction Producer surp;

TS=CS+PS;

*post-I&E reduction welfare gain;

end;

else do; *do if there is no

reduction;

percent=.;

IEchange=.;

lbs=oldlbs;

price=price2008;

CS=0;

GR=0;

PS=0;

TS=CS+PS;

end;

end;

*for great lakes assume that the

consumer surplus is equal to the percentage change

in the catch multiplied by the

dockside value of the catch before the change.

based on bishop and holt (2003);

/*FLAG Rule of Thumb*/*else if

region="greatlakes" and cfspecies~="blank" and negprice~=1 then do;

*else if cfspecies~="blank" and

negprice~=1 then do;/*FLAG Rule of Thumb*/

else if 1=2 then do;/*FLAG Rule of

Thumb*/

if &ievar.~=. and &ievar.~=0

then do;

percent=&iepercent.;

IEchange=&ievar.;

lbs=&ievar.*rbschd+oldlbs;

CSz=(lbs/oldlbs-1)*dollars2008;

CS=CSz*percent;

if CS~=0 then do;

price =

(1/2*(price2008*oldlbs+price2008*lbs)-CSz)/(.5*(lbs+oldlbs));

elasticity=(lbs/oldlbs-1)/(price/price2008-1);

end;

else do;

price=price2008;

end;

GR=price*lbs-price2008*oldlbs;

PS=GR*ABT_NB_Ratio*percent;

TS=CS+PS;

end;

else do;

percent=.;

IEchange=.;

lbs=oldlbs;

elasticity=.;

price=price2008;

CS=0;

GR=0;

Page 27
p4com_main_03.21.11.txt

PS=0;

TS=CS+PS;

end;

end;

*for species where landings data are

missing assume there is no consumer surplus

and estimate producer surplus

assuming no change in prices;

*else if cfspecies="blank" |

negprice=1 then do;

else if 1=1 then do;

if &ievar.~=. and &ievar.~=0

then do;

percent=&iepercent.;

IEchange=&ievar.;

lbs=&ievar.*rbschd+oldlbs;

elasticity=.;

CS=0;

price=price2008;

GR=price*IEchange*rbschd;

PS=GR*ABT_NB_Ratio*&iepercent.;

TS=CS+PS;

end;

else do;

percent=.;

IEchange=.;

lbs=oldlbs;

elasticity=.;

price=price2008;

CS=0;

GR=0;

PS=0;

TS=CS+PS;

end;

end;

end;

****************;

****************;

*Alternatively, for all species,

assume there is no consumer surplus

and estimate producer surplus

assuming no change in prices;

if optionname="&opt._0" then do;

if &ievar.~=. and &ievar.~=0

then do;

percent=&iepercent.;

IEchange=&ievar.;

lbs=oldlbs;

elasticity=0;

CS=0;

price=price2008;

GR=price*IEchange*rbschd;

PS=GR*ABT_NB_Ratio*&iepercent.;

TS=CS+PS;

end;

else do;

percent=.;

IEchange=.;

Page 28
p4com_main_03.21.11.txt

lbs=oldlbs;

elasticity=.;

price=price2008;

CS=0;

GR=0;

PS=0;

TS=CS+PS;

end;

end;

****************;

****************;

%mend;

%optionmac2;

*Calculate discounted welfare variables for 3 and 7 percent;

%macro discounted(r);

CS&r. =

CS/(1.0&r.**(year-1));

PS&r. =

PS/(1.0&r.**(year-1));

TS&r. =

TS/(1.0&r.**(year-1));

%mend;

%discounted(3);

%discounted(7);

if price<0 then put "flag error the price is " price " for

region = " re " and species = " species_econ;

run;

* 7d Calculate Consumer and Producer Surplus For All Years

(year=61);

proc sql;

create table long61 as select

optionname,region,re,cfspecies,species_econ,lossmode,

iechange,percent,

ABT_NB_Ratio,oldlbs,price2008,dollars2008,

61 as year,

sum(CS) as CS,

sum(PS) as PS,

sum(TS) as TS,

sum(CS3) as CS3,

sum(PS3) as PS3,

sum(TS3) as TS3,

sum(CS7) as CS7,

sum(PS7) as PS7,

sum(TS7) as TS7

from long8 group by

optionname,region,re,cfspecies,species_econ,lossmode,

iechange,percent,

ABT_NB_Ratio,oldlbs,price2008,dollars2008;

quit;

* 7e Annualized 41-year Benefit (year=52);

proc sql;

create table long62 as select

optionname,region,re,cfspecies,species_econ,lossmode,

iechange,percent,

ABT_NB_Ratio,oldlbs,price2008,dollars2008,

62 as year,

CS/&yrsc. as CS,

Page 29
p4com_main_03.21.11.txt

PS/&yrsc. as PS,

TS/&yrsc. as TS,

CS3*(.03*(1+.03)**&yrsc.)/((1+.03)**&yrsc.-1) as CS3,

PS3*(.03*(1+.03)**&yrsc.)/((1+.03)**&yrsc.-1) as PS3,

TS3*(.03*(1+.03)**&yrsc.)/((1+.03)**&yrsc.-1) as TS3,

CS7*(.07*(1+.07)**&yrsc.)/((1+.07)**&yrsc.-1) as CS7,

PS7*(.07*(1+.07)**&yrsc.)/((1+.07)**&yrsc.-1) as PS7,

TS7*(.07*(1+.07)**&yrsc.)/((1+.07)**&yrsc.-1) as TS7

from long61;

quit;

* 7f Combine years 1-60 with total and annualized;

data long9;

set long8 long61 long62;

run;

* 7g Format data of Consumer and Producer Surplus For Years 1-50,

total over 60 years, and annualized over 41 years;

proc sql;

create table step7data as select

optionname label="Name of Option",

region,re,cfspecies,species_econ,lossmode,

rbschd label="Benefits Schedule Percentage",

elasticity,

ABT_NB_Ratio,

percent label="LossMode/IE Species Share of Reduction"

format=percent12.2,

iechange label="Reduction in Lbs of Fish Lost" format=comma30.2,

year label="Year of Benefits Schedule",

oldlbs,

lbs label="Option Annual LBS of Harvest" format=comma30.2,

price2008,

price label="Price Under Option" format=dollar12.2 ,

dollars2008,

GR label="Change in Gross Revenue (Undiscounted)"

format=dollar30.2,

CS label="Change in Consumer Surplus (Undiscounted)"

format=dollar30.2,

PS label="Change in Producer Surplus (Undiscounted)"

format=dollar30.2,

TS label="Change in Total Surplus (Undiscounted)"

format=dollar30.2,

CS3 label="Change in Consumer Surplus (3%)" format=dollar30.2,

PS3 label="Change in Producer Surplus (3%)" format=dollar30.2,

TS3 label="Change in Total Surplus (3%)" format=dollar30.2,

CS7 label="Change in Consumer Surplus (7%)" format=dollar30.2,

PS7 label="Change in Producer Surplus (7%)" format=dollar30.2,

TS7 label="Change in Total Surplus (7%)" format=dollar30.2

from long9

order by optionname,region,re,cfspecies,species_econ,lossmode,year;

quit;

*Data step7data;

* set step7data;

* if rbschd="." then delete;

*RUN;

* Begin Data Check;

proc sql;

create table x as select region,

cfspecies,species_econ,

count(cfspecies) as cfcount

from step7data

Page 30
p4com_main_03.21.11.txt

where year=1

group by region,cfspecies;

quit;

proc sql;

create table x2 as select region,

cfspecies,species_econ,

cfcount,

count(species_econ) as iecount

from x

group by region,cfspecies,species_econ

having count(species_econ)~=cfcount

order by region,cfspecies,species_econ;

quit;

data _null_;

set x2;

by region cfspecies species_econ;

if first.species_econ and species_econ~=cfspecies then

put "Make sure that " species_econ " is reasonably

from a subset of " cfspecies;

run;

* End Data Check;

* 8 Summarize by option and region;

proc sql;

create table step8data as select

optionname label="Name of Option",

region,re,

sum(CS)/1000 as CS label="Change in Consumer Surplus (Undiscounted)"

format=dollar30.1,

sum(PS)/1000 as PS label="Change in Producer Surplus (Undiscounted)"

format=dollar30.1,

sum(TS)/1000 as TS label="Change in Total Surplus (Undiscounted)"

format=dollar30.1,

sum(CS3)/1000 as CS3 label="Change in Consumer Surplus (3%)"

format=dollar30.1,

sum(PS3)/1000 as PS3 label="Change in Producer Surplus (3%)"

format=dollar30.1,

sum(TS3)/1000 as TS3 label="Change in Total Surplus (3%)"

format=dollar30.1,

sum(CS7)/1000 as CS7 label="Change in Consumer Surplus (7%)"

format=dollar30.1,

sum(PS7)/1000 as PS7 label="Change in Producer Surplus (7%)"

format=dollar30.1,

sum(TS7)/1000 as TS7 label="Change in Total Surplus (7%)"

format=dollar30.1

from step7data

where year=62

group by optionname,region,re

order by optionname,region,re;

quit;

* 9 Generate Tables;

* 9a pick a year where benefits are in steady state, rbschd=1;

*NOTE this is not necessarily and error depending on the compliance trajectory for

repowering facilities

benefits may never reach the full total for repowering facilities because of the

biological lag;

data t1;

set step7data;

if year=45;

if round(rbschd,.0001)~=1 then do;

Page 31
p4com_main_03.21.11.txt

put "error flag , rbschd = " rbschd " and it should equal

1";

end;

run;

* 9b collapse data by option, region, and species;

proc sql;

create table t2 as select

optionname,region,

cfspecies,

mean(oldlbs) as oldlbs,

max(oldlbs) as oldlbsQA,

mean(price2008) as price2008,

max(price2008) as price2008QA,

mean(elasticity) as elasticity,

max(elasticity) as elasticityQA,

mean(price) as price,

max(price) as priceQA,

sum(cs) as CS,

sum(ps) as PS,

sum(ts) as TS

from t1

group by optionname,region,cfspecies

order by optionname,region,cfspecies;

quit;

* 9c get option/region totals for all species;

proc sql;

create table t3 as select

optionname,region,"Total" as cfspecies,

sum(oldlbs*percent) as oldlbs,

sum(cs) as CS,

sum(ps) as PS,

sum(ts) as TS

from t1 group by optionname,region;

quit;

* 9d get species-specific impingement specific variables (pounds of

harvest gained);

proc sql;

create table timp as select

optionname,region,cfspecies,

sum(IEchange*percent) as pounds_i

from t1

where lossmode="imp"

group by optionname,region,cfspecies

order by optionname,region,cfspecies;

quit;

* 9e get species-specific entrainment specific variables (pounds of

harvest gained);

proc sql;

create table tent as select

optionname,region,cfspecies,

sum(IEchange*percent) as pounds_e

from t1

where lossmode="ent"

group by optionname,region,cfspecies

order by optionname,region,cfspecies;

quit;

* 9f get all-species-total impingement specific variables (pounds of

harvest gained);

Page 32
p4com_main_03.21.11.txt

proc sql;

create table timpT as select

optionname,region,"Total" as cfspecies,

sum(IEchange*percent) as pounds_i

from t1

where lossmode="imp"

group by optionname,region

order by optionname,region;

quit;

* 9e get all-species-total entrainment specific variables (pounds of

harvest gained);

proc sql;

create table tentT as select

optionname,region,"Total" as cfspecies,

sum(IEchange*percent) as pounds_e

from t1

where lossmode="ent"

group by optionname,region

order by optionname,region;

quit;

* 9f combine datasets into one table, recode species variable;

data t4 (drop= oldlbsQA price2008QA elasticityQA priceQA);

length cfspecies species reg $50;

merge t2 t3 tent timp tentT timpT;

by optionname region cfspecies;

if cfspecies="Total" then ord=100;

else if cfspecies="blank" then ord=50;

else ord=1;

pounds_ie=sum(pounds_e,pounds_i);

if cfspecies="alewife" then species = "Alewife";

else if cfspecies="american.plaice" then species =

"American Plaice";

else if cfspecies="american.shad" then species =

"American Shad";

else if cfspecies="anchovies" then species = "Anchovies";

else if cfspecies="atlantic.cod" then species =

"Atlantic Cod";

else if cfspecies="atlantic.croaker" then species =

"Atlantic Croaker";

else if cfspecies="atlantic.herring" then species =

"Atlantic Herring";

else if cfspecies="atlantic.mackerel" then species =

"Atlantic Mackerel";

else if cfspecies="atlantic.menhaden" then species =

"Atlantic Menhaden";

else if cfspecies="black.bullhead" then species =

"Black Bullhead";

else if cfspecies="black.crappie" then species =

"Black Crappie";

else if cfspecies="black.drum" then species = "Black Drum";

else if cfspecies="blue.crab" then species = "Blue Crab";

else if cfspecies="bluefish" then species = "Bluefish";

else if cfspecies="bluegill" then species = "Bluegill";

else if cfspecies="brown.bullhead" then species =

"Brown Bullhead";

else if cfspecies="bullhead.spp" then species =

"Bullhead";

else if cfspecies="butterfish" then species = "Butterfish";

else if cfspecies="cabezon" then species = "Cabezon";

Page 33
p4com_main_03.21.11.txt

else if cfspecies="california.halibut" then species =

"California Halibut";

else if cfspecies="california.scorpionfish" then species

= "California Scorpionfish";

else if cfspecies="channel.catfish" then species =

"Channel Catfish";

else if cfspecies="com.crabs" then species = "Commercial

Crabs";

else if cfspecies="com.sea.basses" then species =

"Commercial Sea Basses";

else if cfspecies="com.shrimp" then species = "Commercial

Shrimp";

else if cfspecies="crappie" then species = "Crappie";

else if cfspecies="cunner" then species = "Cunner";

else if cfspecies="drums.croakers" then species =

"Drums and Croakers";

else if cfspecies="dungeness.crab" then species =

"Dungeness Crabs";

else if cfspecies="flounders" then species = "Flounders";

else if cfspecies="freshwater.drum" then species =

"Freshwater Drum";

else if cfspecies="leatherjacket" then species =

"Leatherjacket";

else if cfspecies="mackerels" then species = "Mackerels";

else if cfspecies="menhaden.spp" then species =

"Menhaden ";

else if cfspecies="muskellunge" then species =

"Muskellunge";

else if cfspecies="northern.anchovy" then species =

"Northern Anchovy";

else if cfspecies="other.com.species" then species =

"Other Commercial";

else if cfspecies="other.com.crabs" then species =

"Other Commercial Crabs";

else if cfspecies="paddlefish" then species = "Paddlefish";

else if cfspecies="pinfish" then species = "Pinfish";

else if cfspecies="pink.shrimp" then species = "Pink

Shrimp";

else if cfspecies="pollock" then species = "Pollock";

else if cfspecies="rainbow.smelt" then species =

"Rainbow Smelt";

else if cfspecies="red.drum" then species = "Red Drum";

else if cfspecies="red.hake" then species = "Red Hake";

else if cfspecies="rockfishes" then species = "Rockfishes";

else if cfspecies="salmon" then species = "Salmon";

else if cfspecies="sauger" then species = "Sauger";

else if cfspecies="sculpin.spp" then species = "Sculpin ";

else if cfspecies="sculpins" then species = "Sculpins";

else if cfspecies="scup" then species = "Scup";

else if cfspecies="sea.basses" then species = "Sea Basses";

else if cfspecies="searobin" then species = "Searobin";

else if cfspecies="sheepshead" then species = "Sheepshead";

else if cfspecies="silver.hake" then species = "Silver

Hake";

else if cfspecies="silver.perch" then species =

"Silver Perch";

else if cfspecies="skate.species" then species =

"Skate Species";

else if cfspecies="smallmouth.bass" then species =

"Smallmouth Bass";

else if cfspecies="smelts" then species = "Smelts";

else if cfspecies="spot" then species = "Spot";

else if cfspecies="spotted.seatrout" then species =

Page 34
p4com_main_03.21.11.txt

"Spotted Seatrout";

else if cfspecies="stone.crab" then species = "Stone Crab";

else if cfspecies="striped.bass" then species =

"Striped Bass";

else if cfspecies="striped.mullet" then species =

"Striped Mullet";

else if cfspecies="sturgeon.spp" then species =

"Sturgeon ";

else if cfspecies="summer.flounder" then species =

"Summer Flounder";

else if cfspecies="sunfish" then species = "Sunfish";

else if cfspecies="surfperches" then species =

"Surfperches";

else if cfspecies="tautog" then species = "Tautog";

else if cfspecies="walleye" then species = "Walleye";

else if cfspecies="weakfish" then species = "Weakfish";

else if cfspecies="white.bass" then species = "White Bass";

else if cfspecies="white.perch" then species = "White

Perch";

else if cfspecies="whitefish" then species = "Whitefish";

else if cfspecies="windowpane" then species = "Windowpane";

else if cfspecies="winter.flounder" then species =

"Winter Flounder";

else if cfspecies="yellow.perch" then species =

"Yellow Perch";

else if cfspecies="z.trophic.transfer" then species =

"Trophic Transfer";

else if cfspecies="z.trophic.xfer" then species = "Trophic

Transfer";

else if cfspecies="blank" then species = "Other";

else if cfspecies="Total" then species = "Total";

else put "error, No species match for cfspecies variable: "

cfspecies;

*data checks;

if abs(oldlbs-oldlbsQA) >.0001 then put

"error flag oldlbs~=oldlbsQA";

if abs(price2008-price2008QA) >.0001 then put "error flag

price2008~=price2008QA";

if abs(elasticity-elasticityQA) >.0001 then put "error flag

elasticity~=elasticityQA";

if abs(price-priceQA) >.0001 then put

"error flag price~=priceQA";

if region="calif" then

reg="California";

else if region="greatlakes" then

reg="Great Lakes";

else if region="gulfmexico" then

reg="Gulf of Mexico";

else if region="inland" then

reg="Inland";

else if region="midatlantic" then

reg="Mid-Atlantic";

else if region="northatlantic" then reg="North

Atlantic";

else if region="southatlantic" then reg="South

Atlantic";

run;

proc sort data=t4 out=t5; by optionname reg ord cfspecies; run;

* 9g format data, drop rows with no benefits;

proc sql;

Page 35
p4com_main_03.21.11.txt

create table t6 as select

optionname label="Name of Option",

reg label="Region Name",

species label="Species Name",

oldlbs/1000 as oldlbs label="Average Annual Harvest

2005-2009 (thousands lbs)" format=comma30.1,

price2008 label="Price Per Pound" format=dollar10.2,

pounds_i/1000 as pounds_i label="Increased Harvest from

Reduced Impingment (thousand lbs)" format=comma30.1,

pounds_e/1000 as pounds_e label="Increased Harvest from

Reduced Entrainment (thousand lbs)" format=comma30.1,

pounds_ie/1000 as pounds_ie label='Increased Harvest from

Reduced I&E (thousand lbs)' format=comma30.1,

elasticity label="Own-Price Elasticity" format=comma10.2,

price label="Steady State Price" format=dollar10.2,

CS/1000 as CS label="Consumer Surplus (thousands 2008$)"

format=dollar30.1,

PS/1000 as PS label="Total Producer Surplus (thousands

2008$)" format=dollar30.1,

TS/1000 as TS label="Total Surplus (thousands 2008$)"

format=dollar30.1

from t5

where pounds_ie~=. and pounds_ie~=0;

quit;

* 9h change zeros to missing;

data Step9Data;

set t6;

if pounds_i =0 then pounds_i =.;

if pounds_e =0 then pounds_e =.;

if pounds_ie =0 then pounds_ie =.;

if price =0 then price =.;

if CS =0 then CS

=.;

if PS =0 then PS

=.;

if TS =0 then TS

=.;

run;

* create 3% data step from step 8 data;

data Step3p (keep=optionname reg PS species);

set Step8Data;

if region="calif" then

reg="California ";

else if region="greatlakes" then

reg="Great Lakes";

else if region="gulfmexico" then

reg="Gulf of Mexico";

else if region="inland" then

reg="Inland";

else if region="midatlantic" then

reg="Mid-Atlantic";

else if region="northatlantic" then reg="North

Atlantic";

else if region="southatlantic" then reg="South

Atlantic";

species = "Total (3% Discount Rate)";

PS=PS3/1;

run;

* create 7% data step from step 8 data;

data Step7p (keep=optionname reg PS species);

Page 36
p4com_main_03.21.11.txt

set Step8Data;

if region="calif" then

reg="California ";

else if region="greatlakes" then

reg="Great Lakes";

else if region="gulfmexico" then

reg="Gulf of Mexico";

else if region="inland" then

reg="Inland";

else if region="midatlantic" then

reg="Mid-Atlantic";

else if region="northatlantic" then reg="North

Atlantic";

else if region="southatlantic" then reg="South

Atlantic";

species = "Total (7% Discount Rate)";

PS=PS7/1;

run;

* Combine 3 and 7 percent discount rates with undiscounted;

data Step37p;

set Step9Data Step3p Step7p;

if species="Total" then

ord=1;

else if species="Total (3% Discount Rate)" then ord=2;

else if species="Total (7% Discount Rate)" then ord=3;

else

ord=0;

run;

proc sort data=Step37p; by optionname reg ord species; run;

data os1 (keep=reg optionname increase);

set Step37p;

if ord=1;

rename pounds_ie=increase;

label increase="Increase in Harvest (thousand lbs)";

run;

data os2 (keep=reg optionname d3);

set Step37p;

if ord=2;

rename ps=d3;

label d3="3% Discount Rate (thousands 2008$)";

run;

data os3 (keep=reg optionname d7);

set Step37p;

if ord=3;

rename ps=d7;

label d3="7% Discount Rate (thousands 2008$)";

run;

proc sort data=os1; by reg optionname; run;

proc sort data=os2; by reg optionname; run;

proc sort data=os3; by reg optionname; run;

data os4;

merge os1 os2 os3;

by reg optionname;

%optionmac2a;

run;

proc sort data=os4; by reg sortx; run;

* 9i generate datasets for species-option-specific tables;

Page 37
p4com_main_03.21.11.txt

*List of regions;

*%let reglist=

California^North Atlantic^Mid-Atlantic^Gulf of Mexico^Great Lakes^South Atlantic;

%let reglist=

California^North Atlantic^Mid-Atlantic^South Atlantic^Gulf of Mexico^Great Lakes;

*List of possible table numbers;

%let numlist=

01 02 03 04 05 06 07 08 09 10

11 12 13 14 15 16 17 18 19 20

21 22 23 24 25 26 27 28 29 30

31 32 33 34 35 36 37 38 39 40

41 42 43 44 45 46 47 48 49 50

51 52 53 54 55 56 57 58 59 60

61 62 63 64 65 66 67 68 69 70

71 72 73 74 75 76 77 78 79 80

81 82 83 84 85 86 87 88 89 90

91 92 93 94 95 96 97 98 99 100

101 102 103 104 105 106 107 108 109 110

111 112 113 114 115 116 117 118 119 120

121 122 123 124 125 126 127 128 129 130

131 132 133 134 135 136 137 138 139 140

141 142 143 144 145 146 147 148 149 150

151 152 153 154 155 156 157 158 159 160

161 162 163 164 165 166 167 168 169 170

171 172 173 174 175 176 177 178 179 180

181 182 183 184 185 186 187 188 189 190

191 192 193 194 195 196 197 198 199 200

201 202 203 204 205 206 207 208 209 210

211 212 213 214 215 216 217 218 219 220

221 222 223 224 225 226 227 228 229 230

231 232 233 234 235 236 237 238 239 240

241 242 243 244 245 246 247 248 249 250;

%macro SStables(start,by);

%do j=1 %to &speciesnum.; /*Five Options (varies with

options)*/

%do i=1 %to 6; /*Six Regions*/

%let T=%eval(&start+&j-1+&by*(&i-1));

Data Table_X_%scan(&numlist,&T.);

length Table $40.;

set Step37p;

Table="Table

&T.:%scan(&speciesoptions.,&j,^):%scan(®list,&i,^)";

if

optionname="%scan(&speciesoptions.,&j,^)";

if

reg="%scan(®list,&i,^)";

run;

%end;

%end;

%mend;

%SSTables(start=&firsttable.,by=&nby.);

* 9j generate datasets for option-specific summary tables;

* 9j1 get annualized data ;

proc sql;

create table sum1 as select

optionname label="Name of Option",

region,re,lossmode,

sum(CS)/1000 as CS label="Change in Consumer Surplus (Undiscounted)

(thousands 2008$)" format=dollar30.1,

Page 38
p4com_main_03.21.11.txt

sum(PS)/1000 as PS label="Change in Producer Surplus (Undiscounted)

(thousands 2008$)" format=dollar30.1,

sum(TS)/1000 as TS label="Change in Total Surplus (Undiscounted)

(thousands 2008$)" format=dollar30.1,

sum(CS3)/1000 as CS3 label="Change in Consumer Surplus (3%)

(thousands 2008$)" format=dollar30.1,

sum(PS3)/1000 as PS3 label="Change in Producer Surplus (3%)

(thousands 2008$)" format=dollar30.1,

sum(TS3)/1000 as TS3 label="Change in Total Surplus (3%) (thousands

2008$)" format=dollar30.1,

sum(CS7)/1000 as CS7 label="Change in Consumer Surplus (7%)

(thousands 2008$)" format=dollar30.1,

sum(PS7)/1000 as PS7 label="Change in Producer Surplus (7%)

(thousands 2008$)" format=dollar30.1,

sum(TS7)/1000 as TS7 label="Change in Total Surplus (7%) (thousands

2008$)" format=dollar30.1

from step7data

where year=16

group by optionname,region,re,lossmode

order by optionname,region,re,lossmode;

quit;

* 9j2 get row-specific data for tables;

%macro sumtables(r,v);

data row&r.imp (keep=optionname region re Imp) row&r.ent (keep=optionname region re

Ent);

set sum1;

Imp=&v.;

Ent=&v.;

if lossmode="imp" then output row&r.imp;

else if lossmode="ent" then output row&r.ent;

run;

proc sql;

create table x&r. as select

&r as row,

i.optionname as ioptionname,i.re as ire,

e.optionname as eoptionname,e.re as ere,

i.imp,

e.ent,

sum(i.imp,e.ent) as iande

from row&r.imp as i full join row&r.ent as e

on i.optionname=e.optionname and

i.re=e.re;

quit;

data row&r.;

set x&r.;

if ioptionname~=" " then optionname=ioptionname;

else optionname=eoptionname;

if ire~=" " then re=ire;

else re=ere;

%mend;

%sumtables(1,CS);

%sumtables(2,PS);

%sumtables(3,TS);

%sumtables(4,TS3);

%sumtables(5,TS7);

* 9j3 combine rows into one table;

data sum2;

set row1 row2 row3 row4 row5;

run;

proc sort data=sum2 out=sum3; by re optionname row; run;

Page 39
p4com_main_03.21.11.txt

* 9j4 generate option-specific table data;

%macro summarybyoption(base,opt,oname);

data baseline option ;

set sum3;

if optionname="&base." then output baseline;

else if optionname="&opt." and row in (3,4,5) then output option;

run;

proc sql;

create table sum4 as select

o.re,7 as row,

o.imp/b.imp as imp,

o.ent/b.ent as ent,

o.iande/b.iande as iande

from baseline as b left join option as o

on b.re = o.re and

b.row = o.row

where o.row=3;

quit;

data option2;

set option;

row=row+5;

run;

data sum5;

length rowname $80;

set baseline sum4 option2;

if row=1 then rowname="Baseline Consumer Surplus Lost

(Undiscounted)";

else if row=2 then rowname="Baseline Producer Surplus Lost

(Undiscounted)";

else if row=3 then rowname="Baseline Welfare Loss (Undiscounted)";

else if row=4 then rowname="Baseline Welfare Loss (3% discount)";

else if row=5 then rowname="Baseline Welfare Loss (7% discount)";

else if row=7 then rowname="% Reduction in Total Losses From

Rule";

else if row=8 then rowname="Welfare Gain (Undiscounted)";

else if row=9 then rowname="Welfare Gain (3% Discount)";

else if row=10 then rowname="Welfare Gain (7% Discount)";

label

re ="region (short)"

row ="Row Number"

imp ="Imingement"

ent ="Entrainment"

iande ="Total";

format imp ent iande comma30.1;

Option="&oname";

run;

proc sort data=sum5 out=&oname; by re row; run;

data outloc.&oname.;

set &oname;

run;

%mend;

%optionmac3;

%let relist=

CA^NA^MA^GM^GL^SA;

* 9j5 generate option-specific tables;

%macro sumtables(start,by);

%do j=1 %to &rnum.; *number of options;

Page 40
p4com_main_03.21.11.txt

%do i=1 %to 6; *6 regions;

%let t=%eval(&start+&j-1+&by*(&i-1));

Data Table_X_%scan(&numlist,&T.);

retain rowname imp ent iande;

set %scan(®ionoptions,&j,^);

if re="%scan(&relist,&i,^)";

run;

%end;

%end;

%mend;

*%sumtables(7,&nby);

%sumtables(%eval(&firsttable+&speciesnum),&nby);

* 10 Export data to excel;

%export(step1data,"&outloc.&output",step1data);

%export(step2data,"&outloc.&output",step2data);

%export(step3data,"&outloc.&output",step3data);

%export(step4data,"&outloc.&output",step4data);

%export(step5data,"&outloc.&output",step5data);

%export(step6data,"&outloc.&output",step6data);

*%export(step7data,"&outloc.&output",step7data);

%export(step8data,"&outloc.&output",step8data);

%export(step9data,"&outloc.&output",step9data);

* 11 Generate National Total Tables;

proc sql;

create table nat1 as select

row,optionname,

"TL" as re,

case

when row=3 or row=8 then "Undiscounted"

when row=4 or row=9 then "3 Percent"

when row=5 or row=10 then "7 Percent"

else "Delete"

end as Discount,

sum(imp) as imp,

sum(ent) as ent,

sum(iande) as iande

from sum3 group by row,optionname;

create table nat2 as select

row,optionname,re,

case

when row=3 or row=8 then "Undiscounted"

when row=4 or row=9 then "3 Percent"

when row=5 or row=10 then "7 Percent"

else "Delete"

end as Discount,

sum(imp) as imp,

sum(ent) as ent,

sum(iande) as iande

from sum3 group by row,optionname,re;

quit;

* 11a drop irrelevent rows, format data;

data nat3 (keep=optionname region imp ent iande discount s row) ;

retain optionname discount region imp ent iande s row;

length region $30.;

set nat2 nat1;

if discount~="Delete";

if re="CA" then region="California";

else if re="GL" then region="Great Lakes";

Page 41
p4com_main_03.21.11.txt

else if re="GM" then region="Gulf of Mexico";

else if re="MA" then region="Mid-Atlantic";

else if re="NA" then region="North Atlantic";

else if re="SA" then region="South Atlantic";

else if re="TL" then region="National Total";

if re="CA" then s=1;

else if re="GL" then s=6;

else if re="GM" then s=5;

else if re="MA" then s=3;

else if re="NA" then s=2;

else if re="SA" then s=4;

else if re="TL" then s=7;

format imp ent iande dollar30.1;

label region="Region"

imp="Impingement"

ent="Entrainment"

iande='I&E'

discount="Discount Rate";

run;

* 11b sort data;

proc sort data=nat3 out=nat4; by optionname row s; run;

* 11c insert blank rows;

data blank;

set nat4;

by optionname row;

if first.row;

region="Blank Row";

imp=.;

ent=.;

iande=.;

s=0;

run;

data nat5;

set nat4 blank;

run;

* 11d sort for printing;

proc sort data=nat5 out=nat6; by optionname row s; run;

* generate national total option-specific tables;

%macro nattables(start);

%do j=1 %to &natnum.;

%let t=%eval(&start+&j-1);

Data Table_X_&t.;

set nat6;

if

optionname="%scan(&natoptions,&j,^)";

run;

%end;

%mend;

%nattables(%eval(&firsttable+&nby*6));

%macro tableexport;

%do i=2 %to 9;

%export(Table_x_0&i,"&outloc.&tables",Table_x_0&i);

%end;

%let to=%eval(&nby*6+&natnum+&firsttable-1);

%do i=10 %to &to.;

Page 42
p4com_main_03.21.11.txt

%export(Table_x_&i,"&outloc.&tables",Table_x_&i);

%end;

%mend;

*%tableexport;

*PRINT REGION TABLES;

%macro printit(var,var2);

%do j=1 %to 6; /*Regions 1 - 6*/

%let region=%scan(®list,&j,^);

%let countlist=0^1^2^3^3^5;

%do i=1 %to &nby.; /*13 Tables Per Region FLAG OPTION-SPECIFIC

STEP!!*/

%if &i<=&speciesnum. %then %do; /*5 species tables per

region FLAG OPTION-SPECIFIC STEP!!*/

Title;

*Title1 "Table

%scan(&numlist,(&j-1)*&nby+&firsttable+&i-1)A : Imp, Ent, and I&E";

Title1 "Table

%eval(%scan(&numlist,((&j-1)*4+&i)*2-1+&firsttable-1)+%scan(&countlist,&j,^)) : Imp,

Ent, and I&E";

Title2 "®ion : Option =

%scan(&TableTitles,&i,^)";

proc print

data=Table_X_%scan(&numlist,(&j-1)*&nby+&firsttable+&i-1) noobs label;

var &var. species pounds_i pounds_e

pounds_ie

;

where species~="Total (3% Discount Rate)"

and

species~="Total (7% Discount

Rate)";

run;

*Title1 "Table

%scan(&numlist,(&j-1)*&nby+&firsttable+&i-1)B : Econ Tables:";

Title1 "Table

%eval(%scan(&numlist,((&j-1)*4+&i)*2+&firsttable-1)+%scan(&countlist,&j,^)) : Econ

Tables:";

Title2 "®ion : Option =

%scan(&TableTitles,&i,^)";

proc print

data=Table_X_%scan(&numlist,(&j-1)*&nby+&firsttable+&i-1) noobs label;

var &var. species oldlbs price2008 pounds_ie

PS;

run;

%end;

%if &i=5 %then %do; /*8 option tables per region FLAG

OPTION-SPECIFIC STEP!!*/

Title;

Title1 "Table

%eval(%scan(&numlist,((&j-1)*4+&i)*2+&firsttable-1)+%scan(&countlist,&j,^)-1) :

Option Summary:";

Title2 "®ion";

proc print data=os4;

where reg="®ion";

run;

%end;

%end;

%end;

%mend;

*PRINT NATIONAL TABLES;

Page 43
p4com_main_03.21.11.txt

%macro printit2(var);

%let begin=%eval(&firsttable+&nby*6);

%do i=1 %to &natnum;

%let j=%eval(&begin.-1+&i);

title;

title "Table &j: Total Commercial Benefits : Option

= %scan(&nattitles.,&i,^)";

proc print data=Table_X_&j noobs label;

var discount region imp ent iande;

run;

%end;

%mend;

*options orientation=landscape;

*ods rtf body="&printout";

*%printit( , );

*%printit2( );

*ods rtf close;

ods csvall body="&printout3.";

%printit(Table optionname reg, option row re);

*%printit2(optionname discount);

ods csvall close;

%macro nat2;

PROC DATASETS LIB=work nolist;

DELETE national0;

RUN; quit;

%let begin=%eval(&firsttable.+&nby.*6);

%do i=1 %to &natnum;

%let j=%eval(&begin.-1+&i);

title;

title "Table &j: Total Commercial Benefits : Option

= %scan(&nattitles.,&i,^)";

proc append base=national0

data=Table_X_&j;

run;

%end;

%mend;

%nat2;

data national1 (keep=option optionname region discount CS noCS);

set national0;

option=translate(optionname,"","_0");

if option=optionname then CS=iande;

else NoCS=iande;

if discount="3 Percent" then discount ="3% Discount";

else if discount="7 Percent" then discount ="7% Discount";

if region="National Total" then region="Total";

run;

proc sql;

create table outloc.national2 as select

option,region,discount,

sum(CS) as CS,

sum(noCS) as noCS

from national1

group by option,region,discount;

quit;

****adding in additional code needed for the discounting appendix ;

Data Discounting_out;

Page 44
p4com_main_03.21.11.txt

set step7data;

if optionname="baseline_0" then delete;

if optionname="tmn1_0" then delete;

if optionname="tmn2_0" then delete;

if optionname="tmn3_0" then delete;

if optionname="tmn4_0" then delete;

drop re cfspecies rbschd price elasticity ABT_NB_Ratio percent IEchange

oldlbs lbs price2008 dollars2008 GR CS PS TS CS3 CS7 TS3 TS7;

RUN;

** ***merge regional producer surplus across all commercial species;

Proc sql;

create table discounting_out_reg as select

optionname,

region,

year,

sum(PS3) as totPS3 format=dollar30.0,

sum(PS7) as totPS7 format=dollar30.0

from discounting_out group by optionname, region, year;

quit;

*merge national producer surplus across all commercial species;

Proc sql;

create table discounting_out_nat as select

optionname,

year,

sum(PS3) as totPS3 format=dollar30.0,

sum(PS7) as totPS7 format=dollar30.0

from discounting_out group by optionname, year;

quit;

*use national values to create a summary for each option;

Data discounting_out_tmn1;

set discounting_out_nat;

if optionname~="tmn1" then delete;

if year=61 then delete;

if year=62 then delete;

RUN;

Data discounting_out_tmn2;

set discounting_out_nat;

if optionname~="tmn2" then delete;

if year=61 then delete;

if year=62 then delete;

RUN;

Data discounting_out_tmn3;

set discounting_out_nat;

if optionname~="tmn3" then delete;

if year=61 then delete;

if year=62 then delete;

RUN;

Data discounting_out_tmn4;

set discounting_out_nat;

if optionname~="tmn4" then delete;

if year=61 then delete;

if year=62 then delete;

RUN;

%export(discounting_out_nat,"&outloc.&output.",discounting_out_nat)

%export(discounting_out_tmn1,"&outloc.&output.",discounting_out_tmn1)

%export(discounting_out_tmn2,"&outloc.&output.",discounting_out_tmn2)

%export(discounting_out_tmn3,"&outloc.&output.",discounting_out_tmn3)

%export(discounting_out_tmn4,"&outloc.&output.",discounting_out_tmn4)

Page 45
p4com_main_03.21.11.txt

Page 46