BookmarkSubscribeRSS Feed
samwong0107
Calcite | Level 5

Hi all

 

I am writing the code for the long run adjustment for probability of default model and the code fails to run.

 

Would you be so kind to advise the code below? thanks a lot!!

 

%let data = pd.model_EJM;
%let lr_avg = 0.033825737;
%let difference = 0.000001;
%let gap = -0.07;

%macro lr;
%do %until (&PD_diff <= &difference);
   data base;
   set &data;
   alpha = -6.0736;
   beta = 7.1518*beh_pred_pd + 26.2966*fin_pred_pd + 47.0150*qual_pred_pd;
   PD = exp(sum(&gap,alpha,beta)) / sum(1,exp(sum(&gap,alpha,beta)));
   adj_factor = &gap;
   run;

   proc sql;
   create table abc
   as select mean(PD) as avg_PD
   from base;
   quit;

   data abc;
   set abc;
   PD_diff = sum (avg_PD, -1 *&lr_avg);
   run;

   proc sql noprint;
   select round(PD_diff, 0.000001) into: PD_diff
   from abc;
   quit;

   %if &PD_diff > 0 %then %do;
      proc sql noprint;
      select sum(max(adj_factor), - 0.0001) into: gap
      from base;
      quit;
   %end;
   %else %if &PD_diff < 0 %then %do;
      proc sql noprint;
      select sum(max(adj_factor), 0.0001) into: gap
      from base;
      quit;
   %end;
%end;
%mend;
%lr;

The log shows that the PD_diff is not a numerical value therefore cannot run the code....

is there anyway I can fix the code...

thanks a lot!!!

1 REPLY 1
Reeza
Super User

Try using %evalf for the comparison since you have floating point numbers. 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—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
  • 1 reply
  • 751 views
  • 0 likes
  • 2 in conversation