Hello,
I have a dataset 'ds' and I would like to calculate 95CI using _denX and _numX. There are 3 set of _den and _num. I would like to use do loop to calculate them all at once. I am new to sas and tried but failed. 😅 Could anyone guide me on this?
If do loop is not the right way, could you show me the right way? I would like to know as many approach as possible.
Thanks.
/*Sample datset*/
data ds;
infile datalines dsd truncover;
input id _den1 _den2 _den3 _num1 _num2 _num3;
datalines;
1,4,7,6,0,3,2,
2,4,7,6,1,0,3,
3,4,7,6,0,2,1,
4,4,7,6,2,1,0
;
/*Looping code. Failed.*/
data want;
set ds;
do i=1 to 3;
_pi = round((_numi/_deni),.0001);
if _pi=0 then _lowi=0;
if _pi=1 then _highi=100;
if _ pi ne 0 then _lowi=round((1-betainv(.975,(_deni-_numi+1),_numi)),.0001)*100;
if _pi ne 1 then _highi=round((1-betainv(.025,(_deni-_numi),_numi+1)),.0001)*100;
resulti = '['||strip(put(_lowi, 5.1))||', '||strip(put(_highi, 5.1))||']';
end;
run;
... View more