BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
malls
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
SAS_Rob
SAS Employee

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;

 

 

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

You can't compute anything from data where your variable SURG takes on only the value '0' and no other value.

 

 

--
Paige Miller
malls
Calcite | Level 5

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 

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
malls
Calcite | Level 5

many thanks 

i'll try this 

SAS_Rob
SAS Employee

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;

 

 

malls
Calcite | Level 5

Both methods works perfectly 

thanks all

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!

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
  • 6 replies
  • 3739 views
  • 0 likes
  • 3 in conversation