dm'log;clear;output;clear'; options ps=256 ls=132 nocenter nodate nonumber; libname output 'C:\Geaghan\Diversity Files\'; *ODS HTML style=minimal rs=none body='C:\your directory here\Diversity TEST.html'; *** change the statement above to direct output to desired directory; data test; infile cards missover; array tax {15} t1-t15; *** You will need to know largest total number of species for the array statement (above), the input statement and and the 2 statements below the input and do loop below. Change all values of "15" to the species number; input t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15; totalnumber = sum(of t1-t15); number = n(of t1-t15); nonzero = 0; shannon = 0; simpson = 0; nonzero = 0; species = 0; do ttt = 1 to 15; ppp = tax{ttt} / totalnumber; if tax{ttt} gt 0 then do; shannon = shannon + ppp*log(ppp); simpson = simpson + tax{ttt}*(tax{ttt}-1); nonzero = nonzero + 1; end; end; cards; 1210 1039 894 236 227 120 10 2 5 1 3 100 50 30 20 1 50 30 10 9 1 235 218 192 87 20 11 11 8 7 4 3 2 2 1 1 ; run; data diversity; set test; shannon = shannon * -1; simpson = simpson / (totalnumber*(totalnumber-1)); if totalnumber gt 0 then MargalefD = (Nonzero - 1) / log(totalnumber); else MargalefD = 0; PielouJ = shannon / log(nonzero); run; proc print data=diversity; var t1-t6 totalnumber number shannon simpson nonzero MargalefD PielouJ; run; *** this print only lists 6 of the species, you can list more or less; *ods html close;