BookmarkSubscribeRSS Feed
JohnKeighley
Obsidian | Level 7

I need to run many binominal tests and have a problem with p= option when attempting to run the tests. I get the following errors when using a variable in the dataset to hold the assumed proportion:


700  ods trace on;
701  ods exclude all;
702  proc freq data=tests(obs=10);
703    by obsr;
704    table cancnts/binomial(p=propp) alpha=0.05;
                                -----
                                22
                                202
ERROR 22-322: Syntax error, expecting one of the following: a numeric constant, a datetime constant.
ERROR 202-322: The option or parameter is not recognized and will be ignored.
705    ods output BinomialTest=BinomialTest;
706    weight canpop;
707  run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE FREQ used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds

WARNING: Output 'BinomialTest' was not created.  Make sure that the output object name, label, or path is spelled correctly.  Also, verify that the
         appropriate procedure options are used to produce the requested output object.  For example, verify that the NOPRINT option is not used.
708  ods trace off;
709  ods exclude none;

 

Is the best option to build a macro with a loop, assign the value to a macro variable, and then call proc freq? I believe that this method would run very slowly. I am using ods to keep the results.

 

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Yes, the option binomial (p=__ ) must contain a numeric value and not a variable name. So if you want the value to change every run of the PROC, you will need to build a macro. Yes, if you have very big data sets, it will run slowly, but I am not aware of any other way to get the job done.

--
Paige Miller
FreelanceReinh
Jade | Level 19

Hello @JohnKeighley,

 

Alternatively, you can compute the p-values in a DATA step as shown below using the formulas from the PROC FREQ documentation. (I assume that you want to specify individual null hypothesis proportions for each BY group; see variable p0 below.)

 

Example:

/* Create sample data for demonstration */

data have;
length byvar $1;
set sashelp.heart;
byvar=smoking_status;
run;

proc sort data=have;
by byvar;
run;

data nullprop;
input byvar :$1. p0;
cards;
. 0.45
H 0.55
L 0.75
M 0.60
N 0.65
V 0.50
;
 
/* Perform two-sided binomial tests with individual null hypothesis proportions of status='Alive' per BY group */

data want(keep=byvar pval);
merge have nullprop;
by byvar;
n+1;
n1+status='Alive';
if last.byvar then do;
  se=sqrt(p0*(1-p0)/n);
  z=(n1/n-p0)/se;
  pval=2*sdf('normal',abs(z));
  output;
  call missing(n, n1);
end;
format pval pvalue.;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 261 views
  • 2 likes
  • 3 in conversation