BookmarkSubscribeRSS Feed
haziqfarhan94
Fluorite | Level 6

hi, I have a logistic model which is get from my colleague, but I want to know how this model work, the sas code using INMODEL option doesn't allow me to use CODE statement. I need to get the formula from this model to generate into SQL code. 

16 REPLIES 16
PGStats
Opal | Level 21

I think you should use the INEST= option in the proc logistic statement with the NOFIT option in the model statement.

 

 

PG
haziqfarhan94
Fluorite | Level 6

Thank you for your reply, I used the existing model to score the data, so Im not use any model statement. Here is my code :

proc logistic inmodel=&INMODEL_LAPSE. NOPRINT;
SCORE DATA = TAB_COMBINE_XP OUT = TAB_COMBINE_XP_1(rename=(p_1=p_1_lp) /*drop=p_0 F_Target_New I_Target_New I_FLAG_XSELL_ADDON I_FLAG_XSELL_PA*/ )fitstat;
run;

 

so I want to know how sas work from the &INMODEL_LAPSE. model to score the data.

Ksharp
Super User

Does you have category variables ? if it was ,then you need get design matrix firstly. @Rick_SAS wrote a blog about it before.

If your variables are numeric type.

Then the following code could get you parameter estimator .

 

proc logistic data=sashelp.class outest=est;
model sex= weight height;
run;

Then y=1*1.1193482105+weight*-0.066360275+height*0.0859144918;

haziqfarhan94
Fluorite | Level 6

Yes my data have category variables. I am not trying to create a new model, I just want to use existing model to score the data using INMODEL option, but I can't figure out how SAS do it for the calculation at the back end because I want to code the SAS script into SQL to score the data. 

Ksharp
Super User

Check CODE statement of PROC LOGISTIC

 

proc logistic.........

model ......

code file=' c:\temp\x.sas ';

run;

 

x.sas contains the logic you want to score new table.

haziqfarhan94
Fluorite | Level 6

I have try it before, but since I am just use the model that have been created (I really don't know how or who created that but the purpose of the model is just to score my current data) , I just use INMODEL= option to call the model and score my current data. INMODEL= option doesn't allowed me to use CODE statement. I'm stuck on this issue forever. 

Ksharp
Super User

You could produce some dummy data to deduce the estimator of each variables.

Assuming there were only two numeric variabls: weight height , make data like 

 

weight  height

0          0  <--  get Intercept

1          0  <-- get weight 

0          1  <-- get height

 

score this data and you will get the parameter estimators .

If you have category variable like SEX ,then you need to know the parameter design (REF , GLM ,EFFECT). or you could try the default value(EFFECT) .

 

Calling @Rick_SAS

Rick_SAS
SAS Super FREQ

Although the OUTMODEL= and INMODEL= options enable you to score your colleague's model, you can't use that technique to automatically generate DATA step code for the model.

 

The easy solution is to ask your colleague to put a CODE statement in his code that fits the model to the data.

You can then look at the DATA step code from the CODE statement, and also use the code to score the model. For an example, see "Techniques for scoring a regression model in SAS".

 

 

 

 

 

Ksharp
Super User

Rick,

OP don't contact that colleague. and can't run that model again, only INMODEL(binary file) left. OP want know how to score a new table in this binary file . Therefore I suggest some dummy data to deduce the parameter estimators . And you have some idea ?

Rick_SAS
SAS Super FREQ

If you are looking for the parameter estimates, you can figure them from the OUTMODEL= data set. However, you will have to write the DATA step evaluation code yourself because you can't use the CODE statement with the INMODEL= option.

 

data ingots;
input Heat Soak r n @@;
datalines;
7 1.0 0 10 14 1.0 0 31 27 1.0 1 56 51 1.0 3 13
7 1.7 0 17 14 1.7 0 43 27 1.7 4 44 51 1.7 0 1
7 2.2 0 7 14 2.2 2 33 27 2.2 0 21 51 2.2 0 1
7 2.8 0 12 14 2.8 0 31 27 2.8 1 22 51 4.0 0 1
7 4.0 0 9 14 4.0 0 19 27 4.0 1 16
;

proc logistic data=ingots outmodel=LogiModel plots=none;
model r/n = Heat | Soak;
ods select ParameterEstimates;
run;

proc print data=LogiModel(rename=(_MISC_=Estimate));
format Estimate bestd16.;
where _TYPE_='E' and _CATEGORY_='E';
run;

proc logistic inmodel=LogiModel;
score data=ingots out=score1;
run;

data Score2;
set Ingots;
mu = -5.99010836 +
0.09633747 * Heat +
0.29955054 * Soak +
-0.00883937 * Heat * Soak;
P_Event = logistic(mu);
run;

proc compare brief method=absolute criterion=1e-6
base=Score1(keep=Heat Soak P_Event)
compare=Score2(keep=Heat Soak P_Event);
run;
Ksharp
Super User

I don't know INMODEL= option will produce a SAS table NOT a binary file . That is to say open that table ,I could see the regression coefficient estimators ? 

Rick_SAS
SAS Super FREQ

KSharp,

I assume you are talking about the OUTMODEL= option. The OUTMODEL= option creates a SAS data set, as demonstrated in the program that I posted. However, you are correct that it is intended for consumption by the INMODEL= option, hence it isn't intended to be  "human readable" and the format is not documented, as far as I know. However, as I have shown, you can "reverse engineer" some information by studying the data set.

Ksharp
Super User

Rick,

If model have some category variables, Shouldn't I know the design matrix firstly ?

There are several parameterization method for CLASS variable, after that I can score the new data ,right ?

Rick_SAS
SAS Super FREQ

KSharp,

Yes. The OP must know all the information that would be in the CLASS and MODEL statements, including the parameters in the model, the order they were specified, the levels of the classification variables, and the parameterization for each class variable. 

 

I'll say again: This is a complicated and error-prone way to solve this problem. For a complicated model with interaction effects, I think it will require a lot of work. A better way is to refit the original data and use a CODE statement. Even the PARAMEST= data set would be easier to use, if that is available.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 16 replies
  • 1675 views
  • 2 likes
  • 4 in conversation