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

If I have data like below, how do I correctly compute the exact binomial CI for the proportion of response/count for each visit/group/subgroup combination?

Visit Group Subgroup response COUNT
1 1 A 1 10
1 1 B 2 8
1 3 A 0 7
1 3 B 2 5
2 1 A 3 7
2 1 B 1 5
2 3 A 2 7
2 3 B 1 5
3 1 A 0 6
3 1 B 1 4
3 3 A 2 6
3 3 B 0 4

 

I used the following code, but all the proportions return as 100% and the CIs are not correct.

 

proc freq data = response;
by visit group subgroup;
weight count;
tables resp / nocum binomial ;
exact binomial;
ods output binomial = binomial (where = (name1 in :("XU", "XL")));
run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

You want this ?

 

data c; 
input
Visit	Group	Subgroup$	response	COUNT;
y=1; wt=response; output;
y=0; wt=count-response; output;
datalines;
1	1	A	1	10
1	1	B	2	8
1	3	A	0	7
1	3	B	2	5
2	1	A	3	7
2	1	B	1	5
2	3	A	2	7
2	3	B	1	5
3	1	A	0	6
3	1	B	1	4
3	3	A	2	6
3	3	B	0	4
;
proc freq data=c noprint;
by visit group subgroup;
weight wt / zero;
tables y / binomial(level='1' cl=exact) ;
exact binomial;
output out=want binomial;
run;


proc print ;run;

Ksharp_0-1738205462033.png

 

View solution in original post

5 REPLIES 5
SAS_Rob
SAS Employee

You only have a single response level for each combination the way the data is now.  For example, notice how in Visit=1, Group=1, Subgroup=A there is only one level to the response, 1.  This is the case for all the subtables.  If this is not what you are expecting, then it might be the way that you entered the data in.  What exactly should each subtable look like?

_Hopper
Obsidian | Level 7
What I want it to do is divide resp/count to get the rate and compute the CI accordingly.
Count = Denominator
Response = Numerator for the proportion
StatDave
SAS Super FREQ

Assuming that each line of your data gives the number of responses in the RESPONSE column and the total number of subjects (or trials) in the COUNT column, then you just need to create two observations from each row to give the number of responses and number of nonresponses. For example, I assume that the first row means that there was 1 response and 9 nonresponses. The following code creates the data as needed and the FREQ step provides the analysis you want. It creates a binary response variable, Y, with levels 0 and 1 (1 representing the response) and the counts needed.

data c; input
Visit	Group	Subgroup$	response	COUNT;
y=1; wt=response; output;
y=0; wt=count-response; output;
datalines;
1	1	A	1	10
1	1	B	2	8
1	3	A	0	7
1	3	B	2	5
2	1	A	3	7
2	1	B	1	5
2	3	A	2	7
2	3	B	1	5
3	1	A	0	6
3	1	B	1	4
3	3	A	2	6
3	3	B	0	4
;
proc freq;
by visit group subgroup;
weight wt;
tables y / binomial(level='1') ;
exact binomial;
run;

_Hopper
Obsidian | Level 7

It generates CIs but there are four rows for each combination of visit,group, and subgroup. All the listing outputs show tables y = 0 even when specifying level = 1

Ksharp
Super User

You want this ?

 

data c; 
input
Visit	Group	Subgroup$	response	COUNT;
y=1; wt=response; output;
y=0; wt=count-response; output;
datalines;
1	1	A	1	10
1	1	B	2	8
1	3	A	0	7
1	3	B	2	5
2	1	A	3	7
2	1	B	1	5
2	3	A	2	7
2	3	B	1	5
3	1	A	0	6
3	1	B	1	4
3	3	A	2	6
3	3	B	0	4
;
proc freq data=c noprint;
by visit group subgroup;
weight wt / zero;
tables y / binomial(level='1' cl=exact) ;
exact binomial;
output out=want binomial;
run;


proc print ;run;

Ksharp_0-1738205462033.png

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1463 views
  • 3 likes
  • 4 in conversation