* Example ; * Length based indices ; %let year=2005; %let species=TORSK; %let maxlength=137.5; %let num=1000000; * numbers in millionns; libname stuv 'M:\prj\design_fish\edata'; * Path to S, T, U & V tables; libname strata 'M:\prj\design_fish\strata'; * Path to datasets with yearly area coverage in nm**2; libname out 'M:\prj\design_fish\Results'; * Where to store results; * Reading station information; data s; set stuv.s&year; if dist<0.5 then dist=0.5; * Very short towed distance is given a reduced weight; if (sampletype in ('1','3')) and (g_cond in ('1','2')); * Sampletype 1&3 for station being a part of the survey design, g_cond 1/2=OK or minor damage; OK=1; n_species="&species"; * This is needed to handle stations with zero catch; keep serial_n stratum main dist OK n_species; run; proc sort data=s; by serial_n n_species; run; * Merge station information with catch info; data st; retain serial_n stratum main n_species subsample W1 OK; * Introducing W1 as a weighting factor; merge stuv.t&year s; by serial_n n_species; if n_species="&species"; if OK=1; w1=c_weight/s_weight/dist; * catch weight / subsample weight / towed distance; if w1=. then w1=c_num/s_num/dist; * Occationally weights are missing; if w1=. then w1=1/dist; * And even zero catches are given a weighting factor; do lgr=2.5 to &maxlength by 5; output; end; * Creating 5 cm length groups; keep serial_n stratum main n_species subsample lgr W1 OK; run; proc sort data=st; by serial_n n_species subsample lgr; run; * Reading length distribution info of subsample; data u; set stuv.u&year; if n_species="&species"; lgr=int(length/5)*5+2.5; * lgr indicates length group; run; proc sort data=u; by serial_n n_species subsample lgr length; run; data stu; merge u st; by serial_n n_species subsample lgr; if OK=1; if frequency=. then frequency=0; * Missing observations set to zero; **************************; w=w1*1852/25; * W1 is catch per nm (towed). Then W is catch per nm**2 (density of fish); /* if &til ne 0 then do; w=F*w1*1852/(&alfa*lengde**&beta); if lengde<&fra then w=F*w1*1852/(&alfa*&fra**&beta); if lengde>&til then w=F*w1*1852/(&alfa*&til**&beta); end;*/ keep serial_n stratum main subsample lgr frequency w ; proc print; run; proc sort data=stu; by stratum main lgr serial_n; run; proc means data=stu noprint; var frequency; by stratum main lgr serial_n; weight w; output out=stu2 sum=; proc print; run; data stu3; merge stu2 strata.a&year; by stratum; frequency=frequency*area/# if frequency ne .; run; proc means data=stu3 noprint; var frequency; by stratum main lgr; output out=stu4 mean=index0 ; run; data out.Leng_index&year; set stu4; drop _FREQ_ _TYPE_; run; * Further results by adding together over Stratum or Main areas;