BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ujjawal
Quartz | Level 8

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 -

VariablesEstimate
Intercept0.001
ABCD0.558356
DEFG0.464783
HIJKL0.111268
MNOP0.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.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

View solution in original post

3 REPLIES 3
PGStats
Opal | Level 21

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
Ujjawal
Quartz | Level 8

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;

PGStats
Opal | Level 21

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 " * ", using the CATX function again. Initially, eq is empty.

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

PG

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 843 views
  • 0 likes
  • 2 in conversation