Hi,
I have a group of 10 exposure variables and a group of 10 outcome variables. I would like to write a macro to regress each outcome variable on each exposure variable (a total of 100 regressions) using GEE with logistic regression, but I am unsure of how to code this. Any help would be much appreciated!
Thanks!
Hi,
first put your variables in a dataset. example:
data have;
input (var1 var2) ($1);
cards;
a b
c d
e f
g h
i j
k l
m n
o p
q r
s t
;
data _null_;
set have;
call symputx(cats('dep',_n_),var1);
call symputx(cats('indvars',_n_),var2);
run;
%macro preliminary_gee();
%do i=1 %to 10;
%do j=1 %to 10;
proc genmod data=xxx descending;
class &&indvars&j pharmid studyarm;
model &&dep&i = &&indvars&j studyarm / dist=bin link=logit type3 wald;
repeated subject = pharmid / type=cs;
run;
%end; %end;
%mend preliminary_gee;
%preliminary_gee()
See about halfway down the page here, though the whole page is useful if you're just starting out with macros.
https://www.ats.ucla.edu/stat/sas/seminars/sas_macros_introduction/default.htm
You can search for:
Thanks so much for this link! After reading the page, I was able to create a macro to regress several outcomes on a single predictor, but I would like to regress all of the outcomes on all of the predictors as well. Are there any more resources you could suggest?
Hi,
post your basic code here, we will help you to create a macro.
Here is the code I am working with so far:
proc genmod data=xxx descending;
class exposure pharmid studyarm (ref='0') / param=ref;
model outcome = exposure studyarm / dist=bin link=logit type3 wald;
repeated subject = pharmid / type=cs;
run;
I would like to create a macro that will regress each of 10 outcome variables on each of 10 exposure variables using this code. As I mentioned above, I was able to write a macro that would regress each outcome on a given group of exposure variables, but I haven't figured out how to loop the macro through all of the exposure variables individually. Here is what I have so far:
%macro preliminary_gee(all_deps, indvars =);
%let k=1;
%let dep = %scan(&all_deps, &k);
%do %while(&dep NE);
proc genmod data=xxx descending;
class &indvars pharmid studyarm;
model &dep = &indvars studyarm / dist=bin link=logit type3 wald;
repeated subject = pharmid / type=cs;
run;
%let k = %eval(&k + 1);
%let dep = %scan(&all_deps, &k);
%end;
%mend preliminary_gee;
In addition, it would be great to suppress the output and to just create a dataset containing the OR estimates from each regression. Again, any ideas you have would be much appreciated.
Thanks!
Nice! But why loop over only the dependents, why not add another do loop and nest over your independents as well?
If you got this far, I think you can get it, but I'm sure ppl here will help regardless.
I don't think JMDECU should do it that way at all. I would "transform" the data such that the independents and dependents are levels of BY variables and use ONE call to PROC GENMOD.
I don't know exactly which output you want from GENMOD but you can figure that out.
Message was edited by: data _null_
Hi,
first put your variables in a dataset. example:
data have;
input (var1 var2) ($1);
cards;
a b
c d
e f
g h
i j
k l
m n
o p
q r
s t
;
data _null_;
set have;
call symputx(cats('dep',_n_),var1);
call symputx(cats('indvars',_n_),var2);
run;
%macro preliminary_gee();
%do i=1 %to 10;
%do j=1 %to 10;
proc genmod data=xxx descending;
class &&indvars&j pharmid studyarm;
model &&dep&i = &&indvars&j studyarm / dist=bin link=logit type3 wald;
repeated subject = pharmid / type=cs;
run;
%end; %end;
%mend preliminary_gee;
%preliminary_gee()
Hi Linlin,
Thanks so much for sending me this code. It worked! Just one last question - is it possible to create a single output dataset containing the odds ratio estimates generated by each regression? I know it is possible to do this when using proc logistic, but I am not sure about proc genmod.
Thanks again!
Two ways.
1. If you persist with the macro loop approach, include a step before the loop to initialize a zero-row target data set. After the PROC GENMOD step but inside the inner loop, include a PROC APPEND.
2. If you adopt data_null_'s suggestion to ditch the macro looping and employ BY processing instead, you should see the stats automatically accumulate in one data set.
jmdecu wrote:
Hi Linlin,
Thanks so much for sending me this code. It worked! Just one last question - is it possible to create a single output dataset containing the odds ratio estimates generated by each regression? I know it is possible to do this when using proc logistic, but I am not sure about proc genmod.
Thanks again!
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.