Hello everyone, I would like to write a bit of code to run a simple proc logistic for every binary variable I have in a data set. I have a %let statement where I have named all of my binary variables, but how would I go about looping through each variable and calling proc logistic?
my current code currently runs all binary variables at the same time.
%let binary = var1 var2 var4 var6 var8 var 1;
proc logistic data=work.dataset;
model outcome = &binary/ clodds=pl clparm=pl;
title "Model single binary variable against outcome";
run;
My recommended option:
https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html
Another option, very similar example except for PROC REG instead.
https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/
Skeleton example for you to modify your code:
https://gist.github.com/statgeek/9603186
@magladde wrote:
Hello everyone, I would like to write a bit of code to run a simple proc logistic for every binary variable I have in a data set. I have a %let statement where I have named all of my binary variables, but how would I go about looping through each variable and calling proc logistic?
my current code currently runs all binary variables at the same time.
%let binary = var1 var2 var4 var6 var8 var 1; proc logistic data=work.dataset; model outcome = &binary/ clodds=pl clparm=pl; title "Model single binary variable against outcome"; run;
A non-macro solution is given here, which probably runs faster than a macro solution
https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html
Lots of good suggestions however, if you have along list of variables, they might not fit in a single macro variable. In that case I would suggest put the list in a dataset and use a call Execute construct to loop through the list.
/* Untested code */
data varlist;
input binvar $;
cards;
var1
var2
var4
var6
var8
var9
;
data _null_;
set varlist;
call symput('binary',trim(binvar));
call execute('
proc logistic data=work.dataset;
model outcome = &binary/ clodds=pl clparm=pl;
title "Model single binary variable against outcome";
run;
');
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.