Search code examples
sassas-macro

SAS: apparent symbolic reference not resolved


I have a problem with unresolved variables in this part of a macro:

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

Specifically, the second data step shows the following error:

 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.

I can't figure out what I'm doing wrong. In particular, I don't understand why the variable in the first data step resolves, but the ones in the second data step don't. Any help would be much appreciated.


Solution

  • In the first data step you created a macro variable "overall". In the second data step you want to create macro variables "ssa", "ssb", "dfa" and "dfb". To decide which macro variable will be created you used macro variable "factor1" and "factor2", but both of them never resolve, because you put them into apostrophes. To resolve macro variable you have to use quotation marks.

    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. First and third if statments are the same. You can combine them using do; end; block.

      if hypothesistype=1 and source="&factor2" then do;
          call symput('ssa', ss);
          call symput('dfa', df);
      end;
    

    Completed code:

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