Search code examples
sassas-macroenterprise-guide

SAS Enterprise guide and conditional Macro Values


I have a simple macro that checks for the existance of a Dataset (DATA01):

%GLOBAL base_exists;
%MACRO does_base_exist();
  %IF %SYSFUNC(exist(DATA_01)) %THEN
    %LET base_exists= 1;
  %ELSE %LET base_exists= 0;

%MEND;

%does_base_exist();

%PUT Base exist check is &base_exists 

The code above is indicated in a Program that is executed before my main Process. The outpu message reads:

"Base exist check is 1"

I have place a confition on my main process to only run when &base_exists is equal to 1 (Which it is). For some reason my main process keeps on failing stating that &base_exists does not exist.

Any ideas on what I'm doing wrong? I am new to EG and more used to working in BASE SAS.

UPDATE: I have appended a 's' to my errro &base_exists, for clarity sake.


Solution

  • You could simplify this even further if you like. A macro is not even necessary. All you need is this line in open code:

    %let base_exists = %sysfunc(exist(DATA_01));
    

    The function will return a value or 0 or 1 so the if statement is not even necessary. Because you don't need the macro, you also won't need the %global statement as any macro defined in open code will be global automatically.