我在宏的这一部分遇到了未解决的变量问题:
%MACRO tukeyaddit(dataset=, factor1=, factor2=, response=);
ods listing close;
proc glm data=&dataset;
class &factor1 &factor2;
model &response = &factor1 &factor2;
ods output overallanova=overall modelanova=model;
run;
quit;
ods listing;
ods output close;
data _null_;
set overall;
if source='Corrected Total' then call symput('overall', ss);
run;
data _null_;
set model ;
if hypothesistype=1 and source='&factor2' then call symput('ssa', ss);
if hypothesistype=1 and source='&factor1' then call symput('ssb', ss);
if hypothesistype=1 and source='&factor2' then call symput('dfa', df);
if hypothesistype=1 and source='&factor1' then call symput('dfb', df);
run;
具体来说,第二个数据步骤显示以下错误:
WARNING: Apparent symbolic reference SSA not resolved.
WARNING: Apparent symbolic reference SSB not resolved.
WARNING: Apparent symbolic reference DFA not resolved.
WARNING: Apparent symbolic reference DFB not resolved.
我无法弄清楚我做错了什么。特别是,我不明白为什么第一个数据步骤中的变量会解析,但第二个数据步骤中的变量不会解析。任何帮助将不胜感激。
答案 0 :(得分:0)
在第一个数据步骤中,您创建了一个宏变量“overall”。 在第二个数据步骤中,您要创建宏变量“ssa”,“ssb”,“dfa”和“dfb”。要决定创建哪个宏变量,您使用宏变量“factor1”和“factor2”,但它们都不会解析,因为您将它们放入撇号中。要解析宏变量,必须使用引号。
data _null_;
set model ;
if hypothesistype=1 and source="&factor2" then call symput('ssa', ss);
if hypothesistype=1 and source="&factor1" then call symput('ssb', ss);
if hypothesistype=1 and source="&factor2" then call symput('dfa', df);
if hypothesistype=1 and source="&factor1" then call symput('dfb', df);
run;
P.S。第一个和第三个if statments
是相同的。您可以使用do; end;
块组合它们。
if hypothesistype=1 and source="&factor2" then do;
call symput('ssa', ss);
call symput('dfa', df);
end;
已完成的代码:
%MACRO tukeyaddit(dataset=, factor1=, factor2=, response=);
%let factor1=%upcase(&factor1);
%let factor2=%upcase(&factor2);
proc glm data=&dataset;
class &factor1 &factor2;
model &response = &factor1 &factor2;
ods output overallanova=overall modelanova=model;
run;
data _null_;
set overall;
if source='Corrected Total' then call symput('overall', ss);
run;
data _null_;
set model ;
if hypothesistype=1 and upcase(source)="&factor2" then call symput('ssa', ss);
if hypothesistype=1 and upcase(source)="&factor1" then call symput('ssb', ss);
if hypothesistype=1 and upcase(source)="&factor2" then call symput('dfa', df);
if hypothesistype=1 and upcase(source)="&factor1" then call symput('dfb', df);
run;
%put _user_;
%mend tukeyaddit;
%tukeyaddit(dataset=sashelp.class, factor1=sex, factor2=age, response=height)