turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Generate Equation based on Estimates

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-02-2015 01:39 PM

I want to generate logistic regression equation based on coefficient estimates. I am trying to find automate solution -

The coefficient estimates are stored in a dataset. They look like below -

Variables | Estimate |

Intercept | 0.001 |

ABCD | 0.558356 |

DEFG | 0.464783 |

HIJKL | 0.111268 |

MNOP | 0.811915 |

score = 0.001 + 0.558356 * ABCD + 0.464783 * DEFG + 0.111269 * HIJKL + 0.811915 * MNOP

p = 1 / (1 + exp(-score))

I want the following equation to be stored in a separate data set. In this data set, there would be a single column named "Equation" and first row contains the equation:

P_1 = 1 / (1 + exp( -(0.001 + 0.558356 * ABCD + 0.464783 * DEFG + 0.111269 * HIJKL + 0.811915 * MNOP))

Note : I am aware of SCORE, OUTMODEL and INMODEL statements in PROC LOGISTIC to calculate predicted probability. But my task is to note down the equation based on estimates.

Accepted Solutions

Solution

08-02-2015
02:02 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ujjawal

08-02-2015 02:02 PM

Build the string using CAT_ functions:

**data want;**

**length eq $200;**

**do until (done);**

** set estimates end=done;**

** if Variable = "Intercept" then **

** eq = catx(" + ", Eq, Estimate);**

** else**

** eq = catx(" + ", Eq, catx(" * ", Estimate, Variable));**

** end;**

**Eq = cats( "P_1 = 1 / (1 + exp( -(", Eq, "))");**

**keep Eq;**

**run;**

PG

PG

All Replies

Solution

08-02-2015
02:02 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ujjawal

08-02-2015 02:02 PM

Build the string using CAT_ functions:

**data want;**

**length eq $200;**

**do until (done);**

** set estimates end=done;**

** if Variable = "Intercept" then **

** eq = catx(" + ", Eq, Estimate);**

** else**

** eq = catx(" + ", Eq, catx(" * ", Estimate, Variable));**

** end;**

**Eq = cats( "P_1 = 1 / (1 + exp( -(", Eq, "))");**

**keep Eq;**

**run;**

PG

PG

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to PGStats

08-04-2015 04:43 PM

Thanks a ton. It works like charm. Could you please explain how it works -

** if Variable = "Intercept" then**

** eq = catx(" + ", Eq, Estimate);**

** else**

** eq = catx(" + ", Eq, catx(" * ", Estimate, Variable));**

** end;**

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ujjawal

08-04-2015 05:40 PM

**CATX** function concatenates values (strings or formatted numbers) and adds the first function argument (e.g. **" + "**) between the concatenated values. So here, the string **eq** is built up by adding to it ( **eq = catx(" + ", eq, something)** ) the intercept estimate or the concatenation of the estimate and the variable name, separated by

Read the manual for more fun details about the CATX, CATS, and CATT functions .

PG