Hi,
I am trying to generate frequencies binomial CI for my response data using below code.
Sadly i'm getting errors when i have only one category(resp='0') in response variable for some categories of by variable.
Can anyone help me with this please ?
thanks
proc sort data=wis.liv OUT= wis.liv_freq; by lev cph ; run;
ods output Binomial=Binomial;
proc freq data = wis.liv_freq;
tables SURG / binomial(level=2);
by lev cph;
run;
ERROR: The BINOMIAL LEV= value is greater than the number of levs for variable SURG.
NOTE: The above message was for the following BY group:
lev=1 cph=h2
ERROR: The BINOMIAL LEV= value is greater than the number of levs for variable SURG.
NOTE: The above message was for the following BY group:
lev=1 cph=h3
ERROR: The BINOMIAL LEV= value is greater than the number of levs for variable SURG.
NOTE: The above message was for the following BY group:
lev=2 cph=h4
ERROR: The BINOMIAL LEV= value is greater than the number of levs for variable SURG.
NOTE: The above message was for the following BY group:
lev=2 cph=h7
ERROR: The BINOMIAL LEV= value is greater than the number of levs for variable SURG.
NOTE: The above message was for the following BY group:
lev=3 cph=h12
ERROR: The BINOMIAL LEV= value is greater than the number of levs for variable SURG.
NOTE: The above message was for the following BY group:
lev=3 cph=h13
ERROR: The BINOMIAL LEV= value is greater than the number of levs for variable SURG.
NOTE: The above message was for the following BY group:
lev=3 cph=h19
ERROR: The BINOMIAL LEV= value is greater than the number of levs for variable SURG.
NOTE: The above message was for the following BY group:
lev=3 cph=h22
ERROR: The BINOMIAL LEV= value is greater than the number of levs for variable SURG.
NOTE: The above message was for the following BY group:
lev=3 cph=h23
ERROR: The BINOMIAL LEV= value is greater than the number of levs for variable SURG.
NOTE: The above message was for the following BY group:
lev=3 cph=h24
ERROR: The BINOMIAL LEV= value is greater than the number of levs for variable SURG.
NOTE: The above message was for the following BY group:
lev=3 cph=h25
ERROR: The BINOMIAL LEV= value is greater than the number of levs for variable SURG.
NOTE: The above message was for the following BY group:
lev=3 cph=h27
ERROR: The BINOMIAL LEV= value is greater than the number of levs for variable SURG.
NOTE: The above message was for the following BY group:
lev=3 cph=h29
ERROR: The BINOMIAL LEV= value is greater than the number of levs for variable SURG.
NOTE: The above message was for the following BY group:
lev=4 cph=h39
ERROR: The BINOMIAL LEV= value is greater than the number of levs for variable SURG.
NOTE: The above message was for the following BY group:
lev=4 cph=h51
ERROR: The BINOMIAL LEV= value is greater than the number of levs for variable SURG.
NOTE: The above message was for the following BY group:
lev=4 cph=h58
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.BINOMIAL may be incomplete. When this step was stopped there were 16
observations and 7 variables.
A suggestion would be to take advantage of the WEIGHT statement with the ZEROS option. You could begin by taking your existing data set and assigning a count of 1.
data wis.liv_freq;
set wis.liv_freq;
ct=1;
run;
Once you do that, you could then create a data set that has all the combinations of the BY variables and the SURG variable and assign a count of 0 to each observation.
data all;
do lev= *assign the levels of lev here;
do cph=...;
do surg=...;
ct=0;
output;
end;
end;
end;
Now if you stack those two data sets together and sort them
data wis.liv_freq2;
set wis.liv_freq all;
proc sort data=wis.liv_freq2;
by lev cph ;
run;
Then you should be able to use the WEIGHT statement in Proc FREQ.
proc freq data = wis.liv_freq2;
weight ct/zeros;
tables SURG / binomial(level=2);
by lev cph;
run;
You can't compute anything from data where your variable SURG takes on only the value '0' and no other value.
program works except for some combinations.
i'm trying to find a way for SAS to compute freq for valid combinations without using the WHERE CLAUSE 16 times
You would have to weed out these levels where there is only one value in a data step (or PROC) before your run PROC FREQ.
many thanks
i'll try this
A suggestion would be to take advantage of the WEIGHT statement with the ZEROS option. You could begin by taking your existing data set and assigning a count of 1.
data wis.liv_freq;
set wis.liv_freq;
ct=1;
run;
Once you do that, you could then create a data set that has all the combinations of the BY variables and the SURG variable and assign a count of 0 to each observation.
data all;
do lev= *assign the levels of lev here;
do cph=...;
do surg=...;
ct=0;
output;
end;
end;
end;
Now if you stack those two data sets together and sort them
data wis.liv_freq2;
set wis.liv_freq all;
proc sort data=wis.liv_freq2;
by lev cph ;
run;
Then you should be able to use the WEIGHT statement in Proc FREQ.
proc freq data = wis.liv_freq2;
weight ct/zeros;
tables SURG / binomial(level=2);
by lev cph;
run;
Both methods works perfectly
thanks all
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.