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 (August 2002, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 30 Aug 2002 12:28:39 -0400
Reply-To:     Quentin McMullen <QuentinMcMullen@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Quentin McMullen <QuentinMcMullen@WESTAT.COM>
Subject:      Re: Is this %if syntax legal?
Comments: To: Jim Groeneveld <J.Groeneveld@ITGROUPS.COM>
Content-Type: text/plain; charset="iso-8859-1"

Jim Groeneveld [mailto:J.Groeneveld@ITGROUPS.COM] wrote in part: > Quentin also very appropriately questioned the use of the > %EVAL function. It > could be a means to force an error indeed if your macro > variables Rank# > (#=1..9) would not be numeric (1..9). But it actually is superfluous, > because the %EVAL function is implicit in macro conditions > (%IF). And it > would generate an error anyway if your macro variable would > not be numeric. > So, whatever your adapted code will be, you may omit the > explicit %EVAL > function.

Hi Jim,

I think what you wrote is only partly correct. Yes, there is am implied %eval() in the %IF when there are integer values being tested. But if the values being tested are non-integer or alpha, it will not run the %eval, it will instead do a character comparison. Thus below the macro language happily evaluates 10<2.5 as true and 10<X as true. The SAS language evaluates 10<2.5 as false, and 10<X creates a note about the uninitialized variable, then evaluates 10<. as false.

68 %macro comp(condition); 69 %if (&condition) %then %put In Macro Language: (&condition) is true; 70 %else %put In Macro Language: (&condition) is false; 71 72 data _null_; 73 if (&condition) then put "In SAS Language: (&condition) is true"; 74 else put "In SAS Language: (&condition) is false"; 75 run; 76 %mend comp; 77 78 %comp(10<2.5) In Macro Language: (10<2.5) is true In SAS Language: (10<2.5) is false 79 %comp(10<X) In Macro Language: (10<X) is true NOTE: Variable X is uninitialized. In SAS Language: (10<X) is false

Given the willingness with which Macro language slips into a character comparison for non-integers, I'm wondering if folks have made practice of coding explicit %eval or %sysevalf in macro conditions that are designed to compare numeric values? Seems like a reasonable error-check to catch bad parameters.

Kind Regards, --Quentin


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