LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (November 2003, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 11 Nov 2003 05:05:41 -0500
Reply-To:   Magnus Mengelbier <magnus.mengelbier@FERRING.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Magnus Mengelbier <magnus.mengelbier@FERRING.COM>
Subject:   Re: A Macro Problem (ref.: SUGI Paper 100-27)
Comments:   To: antoniamarija@NET.HR

Hello

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.

%macro exists(dsn); %sysfunc(exist(&dsn)) %mend exists;

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.

data work.myoutput;

if %exists(work.myinput) then do; set work.myinput;

... some more code here ... end; run;

or better programming ...

data work.myoutput; if (%exists(work.myinput) = 0) then stop;

set work.myinput;

... some code if work.myinput goes here ... run;

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.

HTH

Magnus

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). > >%macro exists(dsn); > %sysfunc(exist(&dsn)); >%mend exists; > >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: > >5285 %exists(temp1e); >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". >1 1 > - > 180 >MPRINT(EXISTS): 1; > >ERROR 180-322: Statement is not valid or it is used out of proper >order. > >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.


Back to: Top of message | Previous page | Main SAS-L page