Reputation: 1772
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.
Upvotes: 1
Views: 976
Reputation: 8513
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.
Upvotes: 4
Reputation: 1772
I have managed to fix it after various attempts. More experience EG users might see this as trivial, but I'll post it anyway, for beginners such as myself.
I had the macro definitions as part of an AutoExec. I moved it into my process flow and connected it to the Process that uses the macro as a conditional variable. It also needs to be set as %GLOBAL in order to use it outside of the scope of a specific program.
Seems to be happy now.
Upvotes: 1