Hello, I received programming notes to update my code using "min" , "max" function. Here is the request : my code (not sure if i did it correctly, because I have 95CI% greater than 100%)
data tbl;
set tbl;
array xcol_ {3} col1-col3;
array xn_ {3} xn1-xn3;
array xcount_ {3} xcount1-xcount3;
array xp_ {3} xp1-xp3;
array xlci_ {3} xlci1-xlci3;
array xuci_ {3} xuci1-xuci3;
retain xn1-xn3 xcount1-xcount3 0;
if anbr=4 and row_text='N' then delete;
else if anbr=4 then do;
if row_text='n' and row_type='N' then do;
do j=1 to 3;
xn_{j} = xcol_{j};
end;
end;
if row_text='Success' and row_type='COUNT' then do;
do j=1 to 3;
xcount_{j} = xcol_{j};
end;
end;
if compress(row_text)='(95%CI)' then do; /* calcualte binomial CI to replace CP CI */
indent=1;
row_text='Two-Sided 95% Confidence Interval for Percentage (Normal Approximation to Binomial)';
xz=quantile('NORMAL', 0.975);
do j=1 to 3;
xp_{j} = xcount_{j} / xn_{j};
xlci_{j}=max(xp_{j} - xz*sqrt(xp_{j}*(1-xp_{j})/xn_{j}),0)*100;
xuci_{j}=min(xp_{j} + xz*sqrt(xp_{j}*(1-xp_{j})/xn_{j}),100)*100;
xcol_{j}='('||compress(put(xlci_{j},8.2))||'%,'||compress(put(xuci_{j},8.2))||'%)';
end;
end;
end;
run;
... View more