The answer is how macros are used by the SAS system. So I will provide an
example of a working way ... and then come to your question.
First off ... just one comment. The macro will work a lot better if you
remove the semicolon after the %sysfunc function.
If you look closely at the macro, you see that the result of %sysfunc(exist
(&dsn)) is not assigned to any macro variable or any other variable such as
in a data step.
Calling the macro like
%let mydataset = %exists(work.tmp1);
will not produce an error but assign a 1 or 0 to the macro variable
mydataset. This data step code will also work.
if %exists(work.myinput) then do;
... some more code here ...
or better programming ...
if (%exists(work.myinput) = 0) then stop;
... some code if work.myinput goes here ...
Now, the error you are getting is because of the following. Just like you
mentioned, the macro executes correctly and returns 1. The 1 is then
interpreted by SAS. The error is because there is not statement in SAS that
is called just "1" so SAS does not understand the command. You can get the
same error if you try to run "laksdjlskajd;" using the program editor. Do
not forget the semicolon ';'.
So, to make a long story shorter, the macro by design returns a value in
such a way that the macro must be called from an expression.
On Tue, 11 Nov 2003 01:14:39 -0800, A Druga <antoniamarija@NET.HR> wrote:
>Hi out there!
>I found this little Macro in SUGI Paper 100-27 (Carpenter).
>As one can see it is very simple and it's task is easy to understand.
>I'm quite new to SAS and now I'm getting following log messages which
>I don't know to interpret:
>MLOGIC(EXISTS): Beginning execution.
>MLOGIC(EXISTS): Parameter DSN has value temp1e
>SYMBOLGEN: Macro variable DSN resolves to temp1e
>NOTE: Line generated by the macro function "SYSFUNC".
>ERROR 180-322: Statement is not valid or it is used out of proper
>MLOGIC(EXISTS): Ending execution.
>The Dataset exists, the macro resolves to the right value and give the
>right output but there is some error which I don't know to eliminate.
>Any hints what I'm doing wrong?
>Thank You in advance.