options pageno = 1 ps=55; /* This program calculates the probability that a county was chosen */ /* for a sample of size 2 given */ /* the other counties in the strata. */ %macro strata(strata,n); data a; infile "/home/grego1/STAT 540/&strata..csv" dlm=',' missover; input county $:11. aad; /* Set up calculation of sampling probabilities */ data c; set a; keep aad; proc transpose data=c out=d; /* The probability of selection for a sample of size 1 */ /* is proportional to traffic intensity */ data e; set d; **Set the probabilities into an array**; total = sum (of col1-col&n); array b col1 - col&n; array c prop1 - prop&n; do i = 1 to &n; c(i) = b(i)/total; end; /* Discard variables we don't need */ data one; set e; keep prop1 - prop&n; data two; set one; array p prop1-prop&n; **CALCULATE ZJ TERMS**; **Begin calculation PIE-i s**; do i=1 to &n; sum1j=0; ind=i; ptempi=p(ind); do j=1 to &n; if j ne i then do; ind=j; ptempj=p(ind); zj=ptempj/(1-ptempj); sum1j=sum1j+zj; end; end; /* Output the probability of selection for a */ /* sample of size 2 */ final1=ptempi*(1+sum1j); output; end; /* Clean-up again */ data three; set two; keep final1; /* This step doesn't make alot of sense anymore */ /* We used to compute these values only for the */ /* two counties we were actually going to sample */ /* from (it saved computational time) */ data four; set a(firstobs=1 obs=3); keep county; data final (rename=(final1=Prob county=County strata=Stratum)); merge three four; strata="&strata"; keep County strata final1; proc print; libname weights "/home/grego1/STAT 540/"; data weights.&strata; **Write appropriate info to file**; set final; %mend; %strata(upurban,3) run;