0
votes

I'm having an issue with resolving macro variables within a macro. I think the issue is the language, and how SAS is sending my statements to the Macro Processor vs. Compiler.

Here's the jist of my code:

 ....some import statements...
%MACRO FCERR(date=);

%LET REMHOST=MainFrame PORT;
SIGNON REMHOST USER=&SYSUSERID. PASSWORD= _PROMPT_;

    %SYSLPUT date=&yymm. ;

RSUBMIT;

            FILENAME FIN "MY.FILE.QUALIFIERS" DISP = shr;

            ......some datasteps......

                LIBNAME METRO "My.File.Qualifiers" DISP=shr;
/********************************************************************

                        *******   *********
                        **        **     **
                        *******   **  *  **
                        **        **   * ** 
                        *******   *********
                                          *
/*******************************************************************/

%IF %SYSFUNC(EXIST(work.EQ_&date._FIN)) %THEN %DO;

            PROC UPLOAD Data = work.EQ_&date._FIN
                        OUT = work.EQ_&date._FIN;

..........a bunch of data steps.................. 

PROC SQL NOPRINT ;
        select count(*) as EQB format=10.0 INTO :EQBEF from EQ_1701_FIN ;
        select count(*) as EQA format=10.0 INTO :EQAFTER from trunc_fin_eq ;
QUIT ;

%PUT &EQBEF;
%PUT &EQAFTER;

%IF %SYSFUNC(STRIP(&EQBEF.)) ~= %SYSFUNC(STRIP(&EQAFTER.)) %THEN %DO;

options emailhost= MYEMAILHOST.ORG ;
filename mail email ' '
to= (&recip.)
subject = "EQ Error QA/QC";

DATA _NULL_;
file mail ;
put "There were potential errors processing the Equifax Error file.";
put "The input dataset contains %SYSFUNC(STRIP(&EQBEF.)) observations.";
put "The output dataset contains %SYSFUNC(STRIP(&EQAFTER.)) observations.";
put "Please check the SAS log for additional details.";
RUN;

%END;

%END;

%ENDRSUBMIT;
%SIGNOFF;

%MEND;

%FCERR(date=&yymm.);

I keep getting an error that is stopping my macro from processing. This is it:

>         SYMBOLGEN:  Macro variable EQBEF resolves to      24707
>         24707
>         MLOGIC(FCERR):  %PUT &EQAFTER
>         WARNING: Apparent symbolic reference EQAFTER not resolved.
>          &EQAFTER
>          SYMBOLGEN:  Macro variable EQBEF resolves to      24707
>          WARNING: Apparent symbolic reference EQAFTER not resolved.
>          WARNING: Apparent symbolic reference EQAFTER not resolved.
>          ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
>                 operand is required. The condition was: %SYSFUNC(STRIP(&EQBEF.)) ~=
>                 %SYSFUNC(STRIP(&EQAFTER.))
>          ERROR: The macro FCERR will stop executing.

Question: Is SAS trying to process my second (i.e. the inside) %IF %THEN statement before it compiles and executes the Data steps above %IF %SYSFUNC(STRIP(&EQBEF.)) ~= %SYSFUNC(STRIP(&EQAFTER.)) %THEN %DO; I can see from the log that SAS is pumping out the error before it is creating the datasets from my datasteps, and I believe that the reason &EQBEF is resolving is because it is creating using PROC UPLOAD;

If so, How can I prevent SAS from executing the second %IF %THEN until the datasteps are processed, since my second select statement in proc sql; is dependent upon the datasteps executing.

Also, I'm having trouble getting my date variable to resolve in proc sql;

E.G.

    PROC SQL NOPRINT ;
        select count(*) as EQB format=10.0 INTO :EQBEF from EQ_1701_FIN ;
        select count(*) as EQA format=10.0 INTO :EQAFTER from trunc_fin_eq ;
QUIT ;

is ideally:

    PROC SQL NOPRINT ;
        select count(*) as EQB format=10.0 INTO :EQBEF from EQ_&DATE._FIN ;
        select count(*) as EQA format=10.0 INTO :EQAFTER from trunc_fin_eq ;
QUIT ;

but &DATE. won't resolve in that proc sql statement, but resolves perfectly fine in all my of my libname statements, etc. Is there some contingency as to why &date. won't resolve within PROC SQL?.....Do I need to have every variable used in my macro referenced in the Parameter List?

2

2 Answers

1
votes

Your macro is running on your local SAS session, but because of the RSUBMIT; and ENDRSUBMIT; statements your SQL code that is generating the macro variable is running on the remote SAS session but the macro statements are referencing the local macro variable.

For example try this simple program that creates a local and a remote macro variable and tries to show the values.

signon rr sascmd='!sascmd';
%let mvar=Local ;
%syslput mvar=Remote ;
%put LOCAL &=mvar;
rsubmit rr;
%put REMOTE &=mvar ;
endrsubmit;
signoff rr;

If you run it in open SAS the %PUT statements will show that MVAR is equal to LOCAL and REMOTE , respectively.

But it you wrap inside a macro a run it

%macro xx;
signon rr sascmd='!sascmd';
%let mvar=Local ;
%syslput mvar=Remote ;
%put LOCAL &=mvar;
rsubmit rr;
%put REMOTE &=mvar ;
endrsubmit;
signoff rr;
%mend xx;
options mprint;
%xx;

You will see that both %PUT statements run in the local server and display the value of the local macro variable.

0
votes

Check the log for the second select

select count(*) as EQA format=10.0 INTO :EQAFTER from trunc_fin_eq ;

If that data set doesn't exist, the macro variable won't be created.

You can set it to 0 to initialize it:

%let EQAFTER=0;