Hi, I got this code to apply to my dataset and to substitute with my variables. there is a macro, that I do not know how to use. I would be very thankful if you could tell me where to substitute my variables (I neither have the dateset where this code worked, so i cannot compare to understand).
%macro AUC_test (input= , pd_est= , default_flag= , Segmento= );
data campione_&segmento.;
set &input.;
*where MOD_RATING_ALLA_DATA_RIF= "&segmento.";
run;
/* AUC calculation */
proc freq data = campione_&segmento. noprint;
table &pd_est. * &default_flag. / missing measures;
output out=_smd measures;
run;
data _smd_&pd_est._&segmento.;
set _smd (keep = _smdrc_ e_smdrc n);
format AUC 17.15;
format Esito $6.;
AUC = (_smdrc_ + 1)/2;
if AUC<= 0.65 then Esito= "ROSSO";
else if 0.65<AUC<= 0.8 then Esito= "GIALLO";
else if AUC>0.8 then Esito= "VERDE";
Segmento="&segmento.";
run;
%mend;
/*BASE*/
%AUC_test (input = Discr , pd_est = PD0Base , default_flag = flag_default_finale, Segmento= IMP );
%AUC_test (input = Discr , pd_est = PD0Base , default_flag = flag_default_finale, Segmento= POE );
%AUC_test (input = Discr , pd_est = PD0Base , default_flag = flag_default_finale, Segmento= PRI );
%AUC_test (input = Discr , pd_est = PD0Base , default_flag = flag_default_finale, Segmento= SMB );
/*WEIGHTED*/
%AUC_test (input = Discr , pd_est = PD_weighted , default_flag = flag_default_finale, Segmento= IMP );
%AUC_test (input = Discr , pd_est = PD_weighted , default_flag = flag_default_finale, Segmento= POE );
%AUC_test (input = Discr , pd_est = PD_weighted , default_flag = flag_default_finale, Segmento= PRI );
%AUC_test (input = Discr , pd_est = PD_weighted , default_flag = flag_default_finale, Segmento= SMB );
data AUC_Base;
set _smd_pd0base_imp _smd_pd0base_poe _smd_pd0base_pri _smd_pd0base_smb;
run;
data AUC_Weighted;
set _smd_pd_weighted_imp _smd_pd_weighted_poe _smd_pd_weighted_pri _smd_pd_weighted_smb;
run;
Hello!
Hugh ... long answer. First off ... the code seems to be intended to run as is, i.e. the macro is defined _and_ used there.
The adaption to your tables is done in the /* BASE */ and /* WEIGHTED */ sections of the code, where the Macro is called. Nevertheless, there are some assumptions on the structure of your data coded there.
My question is, how much do you understand of the macro code? I.e. can you "read" macros? And then: Do the SAS statements within the macro make sense to you? That was a way to keep the answers to your question short.
And of course: The person who provided you with the code should be able to tell you how to use it.
--FJa
Lovely. Does that person know how to create a dataset to work with it? There needs to be a MOD_RATING_ALLA_DATA_RIF variable containing codes for "segments" (i.e. those values in "segmento" further in the code).
If (and only if) your dataset meets the demands on its structure you needed to adjust these lines:
@ari2495 wrote:
/*BASE*/ %AUC_test (input = Discr , pd_est = PD0Base , default_flag = flag_default_finale, Segmento= IMP ); %AUC_test (input = Discr , pd_est = PD0Base , default_flag = flag_default_finale, Segmento= POE ); %AUC_test (input = Discr , pd_est = PD0Base , default_flag = flag_default_finale, Segmento= PRI ); %AUC_test (input = Discr , pd_est = PD0Base , default_flag = flag_default_finale, Segmento= SMB ); /*WEIGHTED*/ %AUC_test (input = Discr , pd_est = PD_weighted , default_flag = flag_default_finale, Segmento= IMP ); %AUC_test (input = Discr , pd_est = PD_weighted , default_flag = flag_default_finale, Segmento= POE ); %AUC_test (input = Discr , pd_est = PD_weighted , default_flag = flag_default_finale, Segmento= PRI ); %AUC_test (input = Discr , pd_est = PD_weighted , default_flag = flag_default_finale, Segmento= SMB );
Where Discr needs to be your input table, PD0Base and PD_weighted columns with the pds and the Segmento= needs to be given a valid segment code (i.e. one in your table).
The WHERE statement filters / selects observations that meet a certain condition. In this case it filters any observation with a variable that contains the "segmento" argument of the macro.
@ari2495 wrote:
data AUC_Base; set _smd_pd0base_imp _smd_pd0base_poe _smd_pd0base_pri _smd_pd0base_smb; run; data AUC_Weighted; set _smd_pd_weighted_imp _smd_pd_weighted_poe _smd_pd_weighted_pri _smd_pd_weighted_smb; run;
And these lines as well ... as the macro produces intermediate tables reflecting the arguments given to it.
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.