SAS:明显的符号引用未解析

SAS: apparent symbolic reference not resolved

我在宏的这一部分遇到未解析变量的问题:

    %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.

我不知道我做错了什么。特别是,我不明白为什么第一个数据步骤中的变量解析,但第二个数据步骤中的变量却没有。任何帮助将不胜感激。

在第一个数据步骤中,您创建了一个宏变量 "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)