BookmarkSubscribeRSS Feed
Bar34gir34
Calcite | Level 5

Hi everyone,

 

I need to write a code that can generate gini coeff. for every variable and create an example table like this;

example:

PredictorGini Coef
CC_RSK_AMT0,7
CC_APP_CNT_L12M0,6
OD_APP_CNT_L12M0,4
CNSMR_APP_CNT_L12M0,266666667
MRTG_APP_CNT_L12M0,116666667
BANKA_SAY0,6
TOPLAM_RISK_MEMZUC0,6
TOPLAM_RISK_MEMZUC_20,6
LIMIT_ALL0,6
LIMIT_20,6
LIMIT_ORAN0,6
RISK_ORAN0,6

 

 

and my code is ;

 

data your_data;
   set WORK.GINI_COEFF_DENEME;
run;

%let predictors = CC_RSK_AMT CC_APP_CNT_L12M OD_APP_CNT_L12M CNSMR_APP_CNT_L12M 
                 MRTG_APP_CNT_L12M BANKA_SAY TOPLAM_RISK_MEMZUC 
                 TOPLAM_RISK_MEMZUC_2 LIMIT_ALL LIMIT_2
                 LIMIT_ORAN RISK_ORAN;

* Initialize the Gini coefficient table with necessary columns;
data gini_table;
   length Predictor $50. Gini_Coef 8.;
   keep Predictor Gini_Coef;
run;

%macro calculate_gini;
   %let i = 1;
   %let predictor = %scan(&predictors, &i);
   %do %while(&predictor ne );
      * Run logistic regression for the current predictor;
      proc logistic data=your_data;
         model FIY_HAS_F(event='1') = &predictor;
         roc 'ROC' &predictor;
         ods output ROCInfo=roc_info;
      run;

      * Check if the model converged;
      data _null_;
         set roc_info;
         if _N_ = 1 then call symputx('model_converged', '1');
         else call symputx('model_converged', '0');
      run;

      %if &model_converged = 0 %then %do;
         %put WARNING: Model did not converge for predictor &predictor;
         %let i = %eval(&i + 1);
         %let predictor = %scan(&predictors, &i);
         %continue;
      %end;

      * Extract the AUC from the ROCInfo table and calculate Gini coefficient;
      data auc_data(keep=Predictor Gini_Coef);
         set roc_info;
         if ROCModel = 'ROC' and ROCType = 'C';
         auc = C;
         Gini_Coef = 2 * auc - 1;
         Predictor = "&predictor";
         output;
      run;

      * Append the Gini coefficient of the current predictor to the Gini table;
      proc append base=gini_table data=auc_data force;
      run;

      * Move to the next predictor;
      %let i = %eval(&i + 1);
      %let predictor = %scan(&predictors, &i);
   %end;
%mend calculate_gini;

* Run the macro to calculate Gini coefficients for all predictors;
%calculate_gini;

* View the Gini coefficient table;
proc print data=gini_table;
   var Predictor Gini_Coef;
run;

 

But it keeps giving this warning and then error:

 

WARNING: Output 'ROCInfo' was not created.  Make sure that the output object name, label, or path is spelled correctly.  Also, verify that the appropriate procedure options are used to produce the requested output object.  For example, verify that  the NOPRINT option is not used

 

ERROR: File WORK.ROC_INFO.DATA does not exist.

 

Can any one please please help me?

5 REPLIES 5
ChrisHemedinger
Community Manager

According to the documentation, ROCInfo is not one of the tables you can specify. Maybe you need ROCAssociation?

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
ballardw
Super User

Run your basic code with the selected options but not ODS output, since it is throwing errors, with the ODS TRACE ON to get the objects created. Use a small data set and perhaps just the option you are having problems with.

The log will show the objects created, basically in the order they appear in the output. That should tell you the name of the object to use on the ODS OUTPUT statement.

ods trace on;
 proc logistic data=your_data;
         model FIY_HAS_F(event='1') = &predictor;
         roc 'ROC' &predictor;

      run;
ods trace off; /* turn it off when done*/

 

 

Ksharp
Super User
%let predictor=age weight height;







%let roc=%qsysfunc(prxchange(s/(\w+)/roc '\1' pred=\1;/,-1,&predictor.));
ods select none;
ods output  ROCAssociation= ROCAssociation;
proc logistic data=sashelp.class ;
model sex=/nofit;
%unquote(&roc.);
run;
ods select all;
data want;
 set ROCAssociation;
 Gini_Coef = 2*Area - 1;
run;
Bar34gir34
Calcite | Level 5
Sorry man , this is my first time using sas for logistic reg. So i need to change model sex=/nofit; to model fiy_has_f=1/ and also should i keep the nofit parameter?
Ksharp
Super User
Yes. you need NOFIT option,since you only want ROC not fitting a real model.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 522 views
  • 3 likes
  • 4 in conversation