Sandra Guerrero
Sandra Guerrero

Reputation: 323

Call a Macro in to another macro sas

I want call a macro in to another macro, this creates a Macro variable which I want used in the other macro. But the output is "WARNING: Apparent symbolic reference TEST33 not resolved."

data Base1;
input v1 v2 v3;
datalines;
1 7 8
;
run;

%let number = 6;
%Macro test1;    
proc sql noprint;
    select
    case when (
        case when &number eq 3 then v1
             when &number eq 6 then v2
             when &number eq 12 then v3
        end ) ge 6 then 1 else 0 end into: Test22 from _last_; quit;
%let Test33 = &Test22;
%Mend test1;

options mlogic mprint symbolgen;
%Macro test2;
%test1
%put &= &Test33;
%Mend;
%test2;

Upvotes: 1

Views: 4103

Answers (1)

Reeza
Reeza

Reputation: 21294

Your code has two mistakes, but not sure if they're genuine mistakes or typo for the demo code.

Either way:

  1. You need to declare the variable inside the macro as GLOBAL if you want to use it outside of the macro. Macro variables have scope, ie local or global.
  2. You reference the data set last while your demo data is called BASE1.

This works fine for me:

data Base1;
input v1 v2 v3;
datalines;
1 7 8
;
run;

%let number = 6;
%Macro test1; 
%global Test33; 
proc sql noprint;
    select
    case when (
        case when &number eq 3 then v1
             when &number eq 6 then v2
             when &number eq 12 then v3
        end ) ge 6 then 1 else 0 end into: Test22 from base1; quit;
%let Test33 = &Test22;
%Mend test1;

options mlogic mprint symbolgen;
%Macro test2;
%test1
%put &= &Test33;
%Mend;
%test2;

Upvotes: 1

Related Questions