BookmarkSubscribeRSS Feed
SIMMII
Calcite | Level 5

This is the SAS macro code my professor has used in one of his examples:

%MACRO logistic_aic_sbc_score(yvariable=,xvariables=,dataset=,minvar=,maxvar=); 

proc datasets;
delete allaicsbc;
run;

%LET nmodels=&maxvar-&minvar+1; 
%DO i= 1 %to &nmodels;

proc datasets;
delete aicsbc model_reg_logistic temp ;
run;

proc logistic data=&dataset  ;
model &yvariable(ref='0') = &xvariables / selection=score best=1 start=&minvar stop=&maxvar;
ods output stat.Logistic.BestSubsets=model_reg_logistic;
run;

data model_reg_logistic; set model_reg_logistic;
keep VariablesInModel;
run;

data temp; set model_reg_logistic;
if _N_ NE &i then delete;
run;

data _null_ ;
set temp;
call symputx('xvar',VariablesInModel);
run;

proc logistic data=&dataset  ;
model &yvariable(ref='0') = &xvar;
ods output Stat.Logistic.FitStatistics=aicsbc;
run; 
data aicsbc;set aicsbc;
drop InterceptOnly;
if criterion ="-2 Log L" then delete;
run;
proc transpose data=aicsbc out=aicsbc;
run;
data aicsbc;set aicsbc;
rename COL1=AIC COL2=SBC;
run;
data aicsbc;set aicsbc;
keep AIC SBC;
run;

proc append base=allaicsbc data=aicsbc force;
run;
%END;

data allaicsbc;
merge allaicsbc model_reg_logistic;
run;

proc print data=allaicsbc;
run;


%MEND logistic_aic_sbc_score;

and I would like to create a table for a file named pred3_num, here is the all subset search code for it:

proc logistic data=pred3_num;
class x5 x7 x8;
model y(ref='0') = x1 x2 x21 x22 x23 x24 x25 x26 x27 x28 x29 xx2 x3 x31 x4 x41 x42 x5-x8 x9 x91 x10 x11 x111 x112 x113 x114 x115 x116 x117 x118 x119 xx11 x12-x14 
x15 x151 x152 /
selection=score best=1;
run;

there 42 explanatory variables. I would like to know how I can modify that MACRO code in order to create a table for my pred3_num data set. 

Thank you

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Is the problem that in the macro the code for PROC LOGISTIC does not have a CLASS statement?

 

Or is there some other problem? In that case you need to explain further.

--
Paige Miller
SIMMII
Calcite | Level 5

This is log for the first bit:

 

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 68         
 69         %logistic_aic_sbc_score(yvariable=y,xvariables=x1 x2 x21 x22 x23 x24 x25 x26 x27 x28 x29 xx2 x3 x31 x4 x41 x42 x5-x8 x9
 69       ! x91 x10 x11 x111 x112 x113 x114 x115 x116 x117 x118 x119 xx11 x12-x14
 70         x15 x151 x152,dataset=pred3_num,minvar=1,maxvar=42);
 
 NOTE: Deleting WORK.ALLAICSBC (memtype=DATA).
 
 NOTE: PROCEDURE DATASETS used (Total process time):
       real time           0.02 seconds
       user cpu time       0.02 seconds
       system cpu time     0.00 seconds
       memory              1557.21k
       OS Memory           24228.00k
       Timestamp           12/03/2023 05:20:18 PM
       Step Count                        1059  Switch Count  2
       Page Faults                       0
       Page Reclaims                     102
       Page Swaps                        0
       Voluntary Context Switches        18
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           16
       
 
 
 NOTE: Deleting WORK.AICSBC (memtype=DATA).
 NOTE: Deleting WORK.MODEL_REG_LOGISTIC (memtype=DATA).
 NOTE: Deleting WORK.TEMP (memtype=DATA).
 
 NOTE: PROCEDURE DATASETS used (Total process time):
       real time           0.02 seconds
       user cpu time       0.02 seconds
       system cpu time     0.00 seconds
       memory              651.34k
       OS Memory           24228.00k
       Timestamp           12/03/2023 05:20:18 PM
       Step Count                        1060  Switch Count  6
       Page Faults                       0
       Page Reclaims                     58
       Page Swaps                        0
       Voluntary Context Switches        46
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           24
       
 
 ERROR: Variable x5 should be either numeric or specified in the CLASS statement.

The log is generating hundreds of other errors, if I include a class statement do you think it will fix most of my other errors? If so, where should I include the class statement in the macro?

 

Thank you

PaigeMiller
Diamond | Level 26

@SIMMII wrote:

The log is generating hundreds of other errors, if I include a class statement do you think it will fix most of my other errors? If so, where should I include the class statement in the macro?


The CLASS statement should fix the X5 problem. With regards to the other errors, it is impossible for me to answer since you didn't show us the other errors.

 

The CLASS statement should go in the macro in the exact same place as it goes in your non-macro code. You probably need modify the macro definition to include a macro parameter containing the list of CLASS variables as well.

 

When you run a macro in SAS, you ought to turn on macro debugging tools, specifically run this line of code before you run the macro

 

options mprint;

 

 

 

Although I question why you need a macro here when you already have written PROC LOGISTIC code that seems to do what you want.

--
Paige Miller

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 3 replies
  • 592 views
  • 0 likes
  • 2 in conversation