Programming the statistical procedures from SAS

linear regression macro - proc glm class statement - unused variables

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

linear regression macro - proc glm class statement - unused variables

Hi,

 

I have a model I would like to run with with a series of independent and dependent variables. I have written a macro to do this. Some of the independent variables are categorical, thus, I included these variables in the class statement. However, I realized that putting unused variables in class statement limits sample for each analysis because the observations used in the regression are limited to those with values for all class statement variables. How can i fix this? Also, any suggestions to make code more efficient would be helpful. My list after %mend is VERY long. Thanks. 

 

code sample:


%macro model(dep, indep);
proc glm data=data1 ;
class var2 (ref=first) indep1 (ref=first) indep2 (ref=first)indep3 (ref=first) indep4 (ref=first) indep5 (ref=first); 

model &dep= &indep var2 var3 var4/solution;
run;

%mend;
%model(dep1, indep1);
%model(dep1, indep2);
%model(dep1, indep3);
%model(dep1, indep4);
%model(dep1, indep5);
%model(dep2, indep1);
%model(dep2, indep2);
.....

 

Thanks in advance!

 


Accepted Solutions
Solution
‎11-07-2016 07:06 PM
Respected Advisor
Posts: 4,756

Re: linear regression macro - proc glm class statement - unused variables

How about :

 

%macro model(dep, indepc, indep);

proc glm data = data1 ;
class var2 &indepc / ref = first;
model &dep = &indep &indepc var2 var3 var4 / solution;
run;

%mend;

you would specify one of indepc or indep in your macro call, depending if your variable is categorical or not.

 

%model(dep1, indep4, );

or

%model(dep2, , indep99);

PG

View solution in original post


All Replies
Solution
‎11-07-2016 07:06 PM
Respected Advisor
Posts: 4,756

Re: linear regression macro - proc glm class statement - unused variables

How about :

 

%macro model(dep, indepc, indep);

proc glm data = data1 ;
class var2 &indepc / ref = first;
model &dep = &indep &indepc var2 var3 var4 / solution;
run;

%mend;

you would specify one of indepc or indep in your macro call, depending if your variable is categorical or not.

 

%model(dep1, indep4, );

or

%model(dep2, , indep99);

PG
Occasional Contributor
Posts: 18

Re: linear regression macro - proc glm class statement - unused variables

Oh, good idea. This works! Thank you. 

Super User
Posts: 18,580

Re: linear regression macro - proc glm class statement - unused variables

The CLASS statement doesn't require a variable, it can be empty.

 

ie the following won't affect your output, where the macro variable is blank. 

 

%let indepn=;

proc glm data=...;

CLASS &indepn;
...
run;quit;
Occasional Contributor
Posts: 18

Re: linear regression macro - proc glm class statement - unused variables

Oh I see. Didn't think of calling up the macro variable in the Class statement. Will try. Thanks.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 227 views
  • 0 likes
  • 3 in conversation