turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- How can I write a macro to execute iterative regre...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-12-2012 11:37 AM

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!

Accepted Solutions

Solution

09-12-2012
04:31 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-12-2012 04:30 PM

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

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-12-2012 11:52 AM

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:

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-12-2012 03:55 PM

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?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-12-2012 11:59 AM

Hi,

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-12-2012 04:09 PM

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!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-12-2012 04:15 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-12-2012 04:25 PM

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.

array y[

array x[

do pharmid =

studyarm = rantbl(

do _n_ =

y[_n_] = rantbl(

x[_n_] = rannor(

end;

output;

end;

by pharmid studyarm X:;

var y:;

by pharmid studyarm dep y;

by dep ind;

ods select none;

ods output GEEEmpPEst=GEEEmpPEst;

by dep ind;

class pharmid studyarm;

model y = x studyarm / dist=bin link=logit type3 wald;

repeated subject = pharmid / type=cs;

ods select all;

Message was edited by: data _null_

Solution

09-12-2012
04:31 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-12-2012 04:30 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-13-2012 11:48 AM

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!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-30-2012 01:33 PM

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!