Date: Wed, 19 Nov 2008 06:25:18 -0500
Reply-To: Jim Groeneveld <jim.1stat@YAHOO.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jim Groeneveld <jim.1stat@YAHOO.COM>
Subject: Re: macro problem -- quoting with %if comparisons
Content-Type: text/plain; charset=ISO-8859-1
Hi Allen,
Then you should use macro quoting, not ordinary quotes as these become part
of the value (they do not enclose a value as with SAS code). But you could
use explicit quotes in comparisons like:
%IF ("&Keyword" EQ "OR") %THEN ......
where the form without explicit quotes
%IF (&Keyword EQ OR) %THEN ......
would compare &Keyword with a NULL string and OR this with a nothing
condition, resulting in an error.
I would recommend to write:
%LET Keyword = %STR(OR);
%IF (&Keyword EQ %STR(OR)) %THEN ......
or
%IF (%QUOTE(&Keyword) EQ %STR(OR)) %THEN ......
Regards - Jim.
--
Jim Groeneveld, Netherlands
Statistician, SAS consultant
home.hccnet.nl/jim.groeneveld
On Wed, 19 Nov 2008 11:14:39 +0100, Allen Ziegenfus <aziegenfus@ANAXIMA.COM>
wrote:
>Hi Ed,
>
>You are correct that the quotes are not needed, but I would argue that they
>are a good idea. For example, consider the following values of idType:
>
>%let idType =OR;
>%let idType =1=1 OR;
>
>Without quotes, the first value causes an error and the second resolves to
>true, regardless of what is on the "right" side of the comparison. Adding
>quotes or %quote ensures the correct behavior.
>
>You might find this example a little exaggerated, but if you are working
>with where clauses (where I noticed this problem) or with state
>abbreviations it is not so far-fetched.
>
>What do other people think? I think always adding quotes for %if comparisons
>is a good practice.
>
>Allen
>
>
>-----Urspr�ngliche Nachricht-----
>Von: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] Im Auftrag von Ed
>Heaton
>Gesendet: Dienstag, 18. November 2008 18:59
>An: SAS-L@LISTSERV.UGA.EDU
>Betreff: Re: macro problem
>
>Jeff;
>
>You don't need the quotes.
>
>%let idType = binary ;
>%macro test() ;
> %if &idType = binary %then %put &idType ;
>%mEnd test ;
>%test()
>%let idType = ;
>%test()
>
>Ed
|