0
votes

I am a relative novice to working with macro variables and seem to have gotten stuck.

I have a macro that opens a table and produces a macro variable &TBL_DIM. using PROC SQL select into.

%macro CREATE_DIM_VAR(tbl, var); %macro _; %mend _;

%syslput tbl = &tbl. / remote=gidwsas;
%syslput var = &var. / remote=gidwsas;

rsubmit;
        PROC SQL NOPRINT;

            *Create SELECT statement for columns we want;
            SELECT ALL_DIM INTO: TBL_DIM SEPARATED BY ', '
            FROM ALLDIM_LIST
            WHERE TBL = "&TBL." AND VAR = "&VAR." 
            ;
        QUIT;
endrsubmit;
%mend;

%CREATE_DIM_VAR(A, GENDER);

When I do the following:

rsubmit;
    %put &TBL_DIM.;
endrsubmit;

It works fine.

But now, when I try to call it within another macro:

%macro Execute(); %macro _; %mend _;

rsubmit;
%do n = 1 %to 10;
    %let THIS_VAR = %scan(&TBL_DIM., &n.));
    %put &THIS_VAR.;
%end;
endrsubmit;

%mend;

%Execute();

I get the error that: WARNING: Apparent symbolic reference TBL_DIM not resolved.

How do I pass TBL_DIM over to the other macro?

EDIT: When I modify %Execute() to run entirely from the Remote Server it works - but I still don't understand conceptually why...

rsubmit;
%macro Execute(); %macro _; %mend _;

    %do n = 1 %to 10;
        %let THIS_VAR = %scan(&TBL_DIM., &n.));
        %put &THIS_VAR.;
    %end;

%mend;
endrsubmit;

rsubmit;
    %Execute();
endrsubmit;
1
The first macro creates TBL_DIM, so it's not surprising that VAR_DIM isn't defined. Assuming that this is just a typo, the problem is presumably due to global vs. local scoping of the macro vars. Try adding '%global tbl_dim;' at the beginning of both macros...Chris Long
@ChrisLong Yes that was a typo sorry!Wolfspirit
@ChrisLong Adding the %GLOBAL seems to resolve the macro variables but they show up as blanksWolfspirit
Re: your edit, you have a local SAS session and a remote SAS session, and they are entirely separate - macro variables created in one don't exist in the other. If you declare and run the Execute macro in your local session, it doesn't have access to the TBL_DIM macro var that exists in the remote session.Chris Long
@ChrisLong This is despite the %EXECUTE macro referencing &TBL_DIM. within a rsubmit session inside the macro?Wolfspirit

1 Answers

1
votes

I'm adding my last comment as an answer, as the reference below gives the definitive reason for the OP's observed behaviour.

Interaction between Compute Services and Macro Processing

http://support.sas.com/documentation/cdl/en/connref/61908/HTML/default/viewer.htm#a001584568.htm

In your non-working case, the local macro processor is processing the code within your rsubmit/endrsubmit block before sending the processed block to the remote server. However, when you declare a macro within the rsubmit/endrsubmit block, the entire macro is submitted and defined remotely.