BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I want to calculate logistic regression model.

The dependent variable is 1/0  (Default/non-Default)

There are 2 predictors: Sex,Age (Each of them is a categorical variable).

Then I want to calculate score card for each variable and each category. 

The code to calculate the scorecard is not clear for me (Someone sent it to me).

I want to ask if there is any other to calculate it?

data raw_tbl;
input sex $ age bad @@;
cards;
2     1    1   1       2    0
1       2    0   2     2    0
2     3    0   2     2    0
1       3    0   1       2    1
2     1    1   2     1    0
2     2    0   2     3    0
1       2    1   2     3    0
2     2    1   1       3    1
1       1    1   2     2    0
1       3    0   1       2    1
1       3    0   2     2    0
2     2    0   2     1    0
2     1    1   2     3    0
2     2    0   2     2    0
1       1    0   1       1    0
2     1    0   1       1    0
2     3    1   2     2    0
1       3    0  2     2    1
2     1    0   2     2    0
2     1    0   2     2    0
;
Run;

proc sql;
select sex,
		count(*) as nr,
        sum(bad) as nr_bads,
		calculated nr_bads/calculated nr as pct_bads format=percent8.2
from raw_tbl
group by  sex
;
quit;

proc sql;
select age,
		count(*) as nr,
        sum(bad) as nr_bads,
		calculated nr_bads/calculated nr as pct_bads format=percent8.2
from raw_tbl
group by  age
;
quit;


proc format;
value Dependent_Fmt 
1 = 'Default' 
0 = 'No_Default';
run;
proc format;
value Sex_Fmt 
1 = 'Male' 
2 = 'Female';
run;
proc format;
value age_Fmt 
1 = 'Till_30' 
2 = '30-40'
3='40+'
;
run;

ods output parameterestimates=Coef_tbl;
proc genmod data=raw_tbl namelen=60 descending ;
class  sex age;
model bad=sex age/ dist=binomial link=logit  type3 wald ;
store MyModel;
output out=raw_data_with_predict  p=P_subscibe xbeta=logit;
/*ODS SELECT ModelANOVA;*/
run;
/**Create data set row_data_with_predict that have row data with predict colmn called :P_subscibe***/

/***Show the coefficents in a data set***/
proc plm source=MyModel;
show parameters;
run;
 
Data est;
set Coef_tbl;
IF Parameter in ('Intercept','Scale') then delete;
Run;


proc sort data=est(KEEP=Parameter Level1 Estimate ProbChiSq) out=est2;
by Parameter Estimate;
Run;


Data est3;
set est2 end=last;
by Parameter Estimate;
retain factor 1 max_s 0 n 0;
odds=exp(Estimate);
if first.Parameter and Estimate<1 then do;
n=n+1;
new_odds=1;
factor=1/odds;
end;
if not first.Parameter then new_odds=factor*odds;
lnodds=LOG(new_odds);
if last.Parameter then do;
factor=1;
max_s=max_s+lnodds;
end;
if last then do;
call symput('max_s',max_s);
call symput('n_var',n);
end;
drop factor;
Run;


data score_card;
set est3;
by Parameter Estimate;
_score_c=lnodds*(1000/&max_s.);
score_c=round(_score_c,1);
KEEP parameter Level1 Estimate ProbChiSqe score_c;
Run;
proc sort data=score_card;
by Parameter level1;
Run;
6 REPLIES 6
quickbluefish
Barite | Level 11
What part is not clear?
Ronein
Onyx | Level 15
Maybe can show other code to calculate score and also learn how from estimate value calculate score . What is theory behind it
PaigeMiller
Diamond | Level 26

There have been books and web sites written on the subject of creating and calculating score cards. That's probably a better place for you to start than to expect us to go over such a huge topic here in the forums.

--
Paige Miller
Ronein
Onyx | Level 15
Is there not a sas procedure to calculate it?
PaigeMiller
Diamond | Level 26

You have ignored the questions that have been asked and ignored the advice to search the resources described. Please answer the questions from @quickbluefish and as suggested do an internet search on this. Please, don't keep asking your question in different ways as a replacement for providing the information asked for or following the advice that has been given.

--
Paige Miller
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1181 views
  • 0 likes
  • 4 in conversation