Obsidian | Level 7

## STATA logistic regression to SAS problem

Hello,

Might someone please help me with a problem I encounter when I attempt to convert STATA logistic regression to SAS?

To keep the question simple, consider the logistic regression with variables:

response: binary 0/1

week: integer from 0 to 10

gender: M/F

age: continuous

In STATA, the code would be:

``logit response i.week i.gender age , or``

From the data, I know that for some weeks, let's say week=2, there is 0 observation with response=1. Running the above code in STATA will result in a warning like the following:

``````2.week != 0 predicts failure perfectly
2.week omitted and 24 obs not used``````

STATA will automatically handle "no event" or very rare event issue, and compute a meaningful odds ratio.

If we fit the same model in SAS using the code:

``````proc genmod;
class week(ref='0') gender;
model response=week gender age / link=logit dist=bin;
lsmeans week gender / ilink diff exp;
run; ``````

We will get the warning of "Hessian matrix is not positive definite" due to the "no event" or very rare event issue. The resulting odds ratios for week are ridiculously large numbers.

Is there any way to re-create omitting the 24 obs in SAS like it does in STATA? I would really like to obtain the same outputs for understanding SAS.

Thank you.

5 REPLIES 5
Lapis Lazuli | Level 10

## Re: STATA logistic regression to SAS problem

Do you just need a statement like this:
where week NE 2;
Obsidian | Level 7

## Re: STATA logistic regression to SAS problem

Thank you for your reply. Nope, after checking in STATA, there are ~600 obs with week=2, but only 24 are omitted in the model. Somehow there is a computed odds ratio for week=2 vs week=0 as 2.08 in STATA, while in SAS it's 10874311.

Obsidian | Level 7

## Re: STATA logistic regression to SAS problem

Thank you for your reply. Nope, after checking in STATA, there are ~600 obs with week=2, but only 24 are omitted in the model. Somehow there is a computed odds ratio for week=2 vs week=0 as 2.08 in STATA, while in SAS it's 10874311.
Super User

## Re: STATA logistic regression to SAS problem

Suggestion:

Provide a data set in the form of data step code so we can actually run your proc genmod code.

BTW, when you run code like this where you do not explicitly name the data set on the proc statement then SAS uses the last created data set. So there is a chance you may be running the procedure against a different data set than you think you are. While an occasionally useful feature for those that forget to provide the data set it is a best practice to always include the data=<use this data set> in your code.

``````proc genmod;
class week(ref='0') gender;
model response=week gender age / link=logit dist=bin;
lsmeans week gender / ilink diff exp;
run; ``````

Obsidian | Level 7

## Re: STATA logistic regression to SAS problem

Thank you! It helped, I just figured out the issue!
Discussion stats
• 5 replies
• 649 views
• 0 likes
• 3 in conversation