/****************************** Simplified version of a Logit Plot Macro by Raymond R. Balise, balise@stanford.edu Useage: %logitplot (dataset, thePredictorVariable, theOutcomeVariable, NumBins); ***************************** */ %macro logitplot(data, pred, outcome, NumBins ); /* 1. Divide the dataset up into the requested number of bins: Name the bin variable "bin"; output into a new dataset called "ranks"*/ proc sort data= &data.; by &pred.; proc rank data = &data. groups = &NumBins. out= ranks; var &pred.; ranks bin; run; /* 2. Calculate/count: (1) The number of events in each bin (sum the outcome variable) (2) The number of observations in each bin (SAS automatically generates this variable, called _FREQ_) (3) The mean value of the predictor in each bin (mean of the predictor variable)*/ proc means data = ranks noprint ; class bin; var &outcome. &pred.; output out=bins sum(&outcome.)=&outcome. mean(&pred.)=&pred.; run; /*3. Calculates the logit in each bin */ data bins; set bins; logit = log((&outcome.)/(_freq_ - &outcome.)); where bin ne .; *gets rid of extra summary observation from PROC MEANS; run; /*4. Plots the logit against the mean value of the predictor in each bin*/ proc gplot data = bins; title2 Estimated logit plot of &pred. predicting &outcome. in the data set &data..; label logit = Est. logit; plot logit * &pred.; symbol v = dot i = j; run; *5. Delete the temporary data files; proc datasets library= work nolist nodetails; delete ranks; delete bins; quit; %mend logitplot; /*Call the macro*/ %logitplot(work.psa, psa, capsule, NumBins=10);