BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

Hello

I would like to calculate PSI stability index for the following  data.

May anyone show the code in SAS to calculate it.

PCT_DEV  is percentile of customers in category from all customers  (Development time)

PCT_last  is percentile of customers in category from all customers (last time)

Data have;
input category  PCT_Dev  PCT_last;
cards;
1 0.9864649963 0.9923499412
2 0.0135350037 0.0076500588
;
Run;
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

/*********** Group=10 ****************/
data have;
input n min max n_good_real n_good_pred  ;
cards;
0 406 468 24 20
1 470 484 45 42 
2 485 495 43 48
3 496 508 64 66
4 509 520 80 78
5 521 531 80 84
6 532 544 85 84
7 545 556 89 87
8 557 571 97 95 
9 572 624 93 96
;
run;

title 'Group=10';
proc sql;
create table temp as
select n label='组号',min label='最小得分' ,max label='最大得分',
n_good_real label='实际好客户个数',
n_good_pred label='预测好客户个数',
 n_good_real/(select sum(n_good_real) from have) as A label='实际好客户占比 A' format=percent7.2,
 n_good_pred/(select sum(n_good_pred) from have) as E label='预测好客户占比 E' format=percent7.2,
 calculated A - calculated E as A_E label='A-E',
 log(calculated A/calculated E) as logAE label='LOG(A/E)' ,
calculated A_E *calculated logAE as PSI from have ; select * from temp; select sum(PSI) as PSI from temp; select n_good_pred into : list separated by ' ' from have; quit; %put &list ; title2 'Chi-Square Goodness-of-Fit Tests'; proc freq data=have order=data; tables n / nocum chisq testf=( &list ) plots(only)=deviationplot(type=dotplot); weight n_good_real; run;

 

 

View solution in original post

7 REPLIES 7
Amir
PROC Star

Hi,

 

Does this paper help?

 

Kind regards,

Amir.

Ronein
Meteorite | Level 14

May you also show here ? Please direct the code to the example I sent,cheers

Amir
PROC Star

Hi,

 

I had never heard of Population Stability Index until your post, so I don't think I'd be best placed to assist.

 

I just Googled "PSI site:sas.com" and the first hit is the paper I sent in my post.

 

If the paper is not helpful then I would suggest you try performing other searches to get results from any site. Or even try posting to statistical forums here and elsewhere, or whatever PSI would be considered a sub-topic of.

 

If you have tried going through the paper and attempted a solution, but are getting errors then try posting the errors here to see if anyone else can help. Alternatively, are you able to ask a colleague of yours? 

 

Lastly, I'm not sure if your confusion is over the general method of how to calculate PSI (which one can Google).

 

HTH.

 

 

Kind regards,

Amir.

Ksharp
Super User

/*********** Group=10 ****************/
data have;
input n min max n_good_real n_good_pred  ;
cards;
0 406 468 24 20
1 470 484 45 42 
2 485 495 43 48
3 496 508 64 66
4 509 520 80 78
5 521 531 80 84
6 532 544 85 84
7 545 556 89 87
8 557 571 97 95 
9 572 624 93 96
;
run;

title 'Group=10';
proc sql;
create table temp as
select n label='组号',min label='最小得分' ,max label='最大得分',
n_good_real label='实际好客户个数',
n_good_pred label='预测好客户个数',
 n_good_real/(select sum(n_good_real) from have) as A label='实际好客户占比 A' format=percent7.2,
 n_good_pred/(select sum(n_good_pred) from have) as E label='预测好客户占比 E' format=percent7.2,
 calculated A - calculated E as A_E label='A-E',
 log(calculated A/calculated E) as logAE label='LOG(A/E)' ,
calculated A_E *calculated logAE as PSI from have ; select * from temp; select sum(PSI) as PSI from temp; select n_good_pred into : list separated by ' ' from have; quit; %put &list ; title2 'Chi-Square Goodness-of-Fit Tests'; proc freq data=have order=data; tables n / nocum chisq testf=( &list ) plots(only)=deviationplot(type=dotplot); weight n_good_real; run;

 

 

Ronein
Meteorite | Level 14
Thanks and great.
I think that you forgot to calculate the Multiplication of (A-E)*(Log (A/E) ) and then sum this values to get PSI.

calculated A - calculated E as A_E label='A-E',
log(calculated A/calculated E) as logAE label='LOG(A/E)',
calculated A_E *calculated logAE as PSI
Ksharp
Super User
OK. I changed my code. Hope someone need it .
jorgelobin
Calcite | Level 5

On this page there is a complete example with all the steps:
https://www.sasdesdecero.com/implementacion-en-sas-del-population-stability-index/

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
  • 7 replies
  • 2661 views
  • 3 likes
  • 4 in conversation