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

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

4 REPLIES 4
PGStats
Opal | Level 21

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
pamplemouse22
Calcite | Level 5

Oh, good idea. This works! Thank you. 

Reeza
Super User

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;
pamplemouse22
Calcite | Level 5

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

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!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

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