## Calculate the probability of a logistic regression

Solved
Occasional Contributor
Posts: 5

# Calculate the probability of a logistic regression

Hi,

How can I calculate the probability of a logistic regression model given the values of independent variables not only by hand but also by SAS? Please show me some sample code.

Accepted Solutions
Solution
‎08-20-2016 01:53 PM
Posts: 4,746

## Re: Calculate the probability of a logistic regression

Try @Ksharp's code. Start by omitting data=test to score the original data (the crops dataset).

PG

All Replies
Super User
Posts: 18,542

## Re: Calculate the probability of a logistic regression

[ Edited ]

This is known as scoring a model.

As of SAS 9.4 there's the CODE statement that will generate the code you need to score your data.

See several of the options with example code here:

http://blogs.sas.com/content/iml/2014/02/19/scoring-a-regression-model-in-sas.html

This thread has a fully worked example that's a manual process BEFORE the availability of the CODE statement.

https://communities.sas.com/t5/SAS-Statistical-Procedures/How-to-determine-logistic-regression-formu...

I'd use the CODE option now.

Posts: 4,746

## Re: Calculate the probability of a logistic regression

Note that the CODE generation is not implemented for all models. I learned the hard way (not in the doc) that I can't get the code for scoring a model containing a constructed spline effect. I am using version 13.1 but I don't see any mention of the feature being added to more recent versions.

PG
Super User
Posts: 9,769

## Re: Calculate the probability of a logistic regression

```There are about three way to score data: CODE , SCORE, STORE statements.
Check documentation example Example 72.16: Scoring Data Sets .

The simplest is SCORE

proc logistic data=Crops;
score data=Test  out=Score1;
run;

```
Occasional Contributor
Posts: 5

## Re: Calculate the probability of a logistic regression

lets say I have the values for x1-x4, how can I find the logistic probability of Crop. What should be the code?
Super User
Posts: 18,542

## Re: Calculate the probability of a logistic regression

@chowfar Have you looked at any of the indicated references? Which ones were unclear?

Solution
‎08-20-2016 01:53 PM
Posts: 4,746

## Re: Calculate the probability of a logistic regression

Try @Ksharp's code. Start by omitting data=test to score the original data (the crops dataset).

PG
☑ This topic is solved.