BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
HitmonTran
Pyrite | Level 9

Hello,

 

I received programming notes to update my code using "min" , "max"  function.  Here is the request :


HitmonTran_0-1713840881064.png

 

 

 

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;  

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

Can you post example input data (as a DATA step with the CARDS statement)?

 

I didn't go through the code, but if the problem is you are getting upper confidence limit of 10000%, then I think the problem may be this line:

xuci_{j}=min(xp_{j} + xz*sqrt(xp_{j}*(1-xp_{j})/xn_{j}),100)*100;

Should be:

xuci_{j}=min(xp_{j} + xz*sqrt(xp_{j}*(1-xp_{j})/xn_{j}),1)*100;

Your value xp_{j} is a proportion (with range 0-1), not a percentage (with range 0-100).

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

View solution in original post

5 REPLIES 5
Quentin
Super User

Can you post example input data (as a DATA step with the CARDS statement)?

 

I didn't go through the code, but if the problem is you are getting upper confidence limit of 10000%, then I think the problem may be this line:

xuci_{j}=min(xp_{j} + xz*sqrt(xp_{j}*(1-xp_{j})/xn_{j}),100)*100;

Should be:

xuci_{j}=min(xp_{j} + xz*sqrt(xp_{j}*(1-xp_{j})/xn_{j}),1)*100;

Your value xp_{j} is a proportion (with range 0-1), not a percentage (with range 0-100).

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
ballardw
Super User

Whatever that first picture might be is unreadable as the text is too small.

Patrick
Opal | Level 21

@ballardw wrote:

Whatever that first picture might be is unreadable as the text is too small.


@ballardw If you click on the picture it shows in a readable size.

Patrick_0-1713929380798.png

 

ballardw
Super User

@Patrick wrote:

@ballardw wrote:

Whatever that first picture might be is unreadable as the text is too small.


@ballardw If you click on the picture it shows in a readable size.

Patrick_0-1713929380798.png

 


Not on my system. The picture got very slightly larger but not enough to read.

Rick_SAS
SAS Super FREQ

Respectfully, you do not need to write your own formula for the confidence interval. PROC FREQ can produce many different CIs for the binomial proportion. The one you are using is called the "Wald" confidence interval and is the default CI when you specify the BINOMIAL option in the TABLES statement.  PROC FREQ automatically handles capping the CI so that it does not include proportions less than 0 or greater than 1.

 

For an example, see the article, "Compute and visualize binomial proportions in SAS."

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 473 views
  • 7 likes
  • 5 in conversation