BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jmdecu
Fluorite | Level 6

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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()

View solution in original post

9 REPLIES 9
Reeza
Super User

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:

A macro program for repeating a procedure multiple times

jmdecu
Fluorite | Level 6

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? 

Linlin
Lapis Lazuli | Level 10

Hi,

post your basic code here, we will help you to create a macro.

jmdecu
Fluorite | Level 6

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!

Reeza
Super User

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. 

data_null__
Jade | Level 19

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.

data sample;
   array y[3];
   array x[3];
   do pharmid = 1 to 10;
      studyarm = rantbl(
12345,.5);
      do _n_ = 1 to dim(y);
         y[_n_] = rantbl(0,.5);
         x[_n_] = rannor(0);
         end;
     
output;
     
end;
  
run;
proc print;
  
run;
proc transpose data=sample out=sample2(rename=(col1=Y)) name=dep;
   by pharmid studyarm X:;
   var y:;
   run;
proc transpose data=sample2 out=sample3(rename=(col1=X)) name=ind;
   by pharmid studyarm dep y;
   run;
proc sort data=sample3;
   by dep ind;
   run;
proc print;
  
run;
ods select none;
ods output GEEEmpPEst=GEEEmpPEst;
proc genmod data=sample3 descending;
  
by dep ind;
   class pharmid studyarm;
   model y = x studyarm / dist=bin link=logit type3 wald;
  
repeated subject = pharmid / type=cs;
   run;
ods select all;
proc print data=GEEEmpPEst;
   run;

Message was edited by: data _null_

Linlin
Lapis Lazuli | Level 10

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()

jmdecu
Fluorite | Level 6

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!  

Howles
Quartz | Level 8

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!  

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 4877 views
  • 6 likes
  • 5 in conversation