c**********e 发帖数: 2007 | 1 Suppose that I have a data set data1, with numerical variables
x, y, z. I would like to do regression y=x if a macro
variable is "a" and do z=x y if the macro variable is not
"a". The following does not work well. How to do it?
%macro regre(var);
%if "&var."="a" %then %do;
proc reg data=data1;
model y=x;
run;
%end;
%else %do;
proc reg data=data1;
model z=x y;
run;
%end;
%mend;
%regre(a);
%regre(b); |
o******6 发帖数: 538 | 2 It is not necessary to use "if then", just create two macro variable which
are dependent variable and independent variable, separately.
【在 c**********e 的大作中提到】 : Suppose that I have a data set data1, with numerical variables : x, y, z. I would like to do regression y=x if a macro : variable is "a" and do z=x y if the macro variable is not : "a". The following does not work well. How to do it? : %macro regre(var); : %if "&var."="a" %then %do; : proc reg data=data1; : model y=x; : run; : %end;
|
c**********e 发帖数: 2007 | 3 Thanks. Your approach would work. But my real problem is to
work on two proc's based a macro variable value. To make it
work, I have to make the above example work with the if else.
【在 o******6 的大作中提到】 : It is not necessary to use "if then", just create two macro variable which : are dependent variable and independent variable, separately.
|
o******6 发帖数: 538 | 4 %macro regression(dep=,indep=);
proc reg data=data1;
model &dep=&indep;
run;
%mend;
%regression(dep=y,indep=x);
%regression(dep=z,indep=x y);
【在 c**********e 的大作中提到】 : Thanks. Your approach would work. But my real problem is to : work on two proc's based a macro variable value. To make it : work, I have to make the above example work with the if else.
|
w***z 发帖数: 28 | 5 u code is ok for me.
what did u mean when u said "not work well"? |
o******6 发帖数: 538 | 6 Yes, the code works but I don't think it is good if I understand what he
said.
【在 w***z 的大作中提到】 : u code is ok for me. : what did u mean when u said "not work well"?
|
c**********e 发帖数: 2007 | 7 Thank you for your input.
I have made my original code compiled. But it seems that,
from MPRINT, the part in %if ... %do; ... %end; is ignored.
It is really weird.
【在 o******6 的大作中提到】 : Yes, the code works but I don't think it is good if I understand what he : said.
|