SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
nexterd
Fluorite | Level 6

Hi,

 

I'd like to calculate prevalence ratios in SAS with a binary outcome having many covariates.

Data look like this roughly:

data have;

input m$ a$ b$ c @@;
datalines;
0 1 0 34 1 2 0 56
1 3 1 54 0 2 1 23
;

 

m is a binary outcome (0 or 1), a (1, 2, or 3) and b (0 or 1) is categorical exposures, and c is continuous one.

 

At first, I calculated odds ratios very easily as follows:

 

proc logistic data=have descending;
class a (ref="1") b (ref="1")  / param=glm;
model m(event="1") = a b c;
lsmeans a  b c/ e ilink;
ods output coef=coeffs;
store out=ques;
run;

 

So I tried calculate prevalence ratios with a macro:

%nlmeans(instore=ques, coef=coeffs, link=logit, options=ratio, title=Relative Risk)

 

But there was a warning message: 

The final Hessian matrix is not positive definite, and therefore the estimated covariance matrix is not full
rank and may be unreliable. The variance of some parameter estimates is zero or some parameters are
linearly related to other parameters.

 

I also tried it using PROC GENMOD

proc genmod data=have descending;
class a (ref="1") b (ref="1") ;
model m = a b c / dist=bin link=log type3 corrb;
estimate "RR for a1" a  1 -1 0  /exp;

estimate "RR for a2" a 1 0 -1  /exp;
estimate "RR for b"b 1 -1  /exp;
estimate "RR for c" c 1  /exp;

run;

 

And I also got a warning message like this:

The relative Hessian convergence criterion of 0.0199906038 is greater than the limit of 0.0001. The
convergence is questionable.
WARNING: The procedure is continuing but the validity of the model fit is questionable.

 

In addition, the direction of estimates is totally different from the results out of PROC LOGISTIC.

For example, while I got the estimate 0.55 and 0.32 for each group of variable "a" from logistic regression, PROC GENMOD showed 1.44 and 3.56, respectively.

 

So I tried dist=poisson instead of bin, but I am not sure if this is correct.

I have reviewed this note (https://support.sas.com/kb/23/003.html) but I guess this was calculated from count data. Mine has a binary outcome.

I've also heard that I could try calculate adjusted prevalence or marginal prevalence. But I have no idea how to calculate this in SAS.

Please help me out to estimate prevalence ratios correctly in this situation. Thanks!

3 REPLIES 3
Ksharp
Super User

"

For example, while I got the estimate 0.55 and 0.32 for each group of variable "a" from logistic regression, PROC GENMOD showed 1.44 and 3.56, respectively.

"

That was supposed to be . PROC LOGISTIC model Y=log(p/1-p), but PROC GENMOD model Y=p . therefore the estimated coefficience is totally different.

 

I think you should put C variable in WEIGHT/FREQ statement ,not as a X variable ,like:

proc genmod data=have descending;
class a (ref="1") b (ref="1") ;
model m = a b / dist=bin link=log type3 corrb;
weight c;

estimate "RR for a1" a  1 -1 0  /exp;
estimate "RR for a2" a 1 0 -1  /exp;
estimate "RR for b"  b 1 -1  /exp;

lsmeans a / diff exp cl;
lsmeans b / diff exp cl;
run;
proc genmod data=have descending;
class  a (ref="1")  b (ref="1") ;
model m = a b / dist=bin link=log type3 corrb;
freq c;
lsmeans a / diff exp cl;
lsmeans b / diff exp cl;
run;

 

And since your X variable are all category variable, you also could try PROC FREQ like:

proc freq order=data data=have;
        tables a*b*m / cmh;
        weight c;
        run;

Further more, about your WARNING message, I think it is due to your data is too sparse.

for example:  when a=1 ,m only have 0 ; a=3 ,m only have 1.

a.k.a you need more data to get what you want.

 

nexterd
Fluorite | Level 6
Many thanks! I also asked this at STAT Forum.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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