Date: Fri, 27 Jul 2001 17:54:29 -0400
Reply-To: Edward Heaton <HEATONE@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Edward Heaton <HEATONE@WESTAT.COM>
Subject: Re: problem with characters in macro %if expression
Content-Type: text/plain; charset="iso-8859-1"
Gabriel;
I tried the following with the same unexpected results.
1 %macro test ;
2 %Let measure = FGT ;
3 %If &measure = GE %then %put measure is ge and measure is &measure
;
4 %mEnd test ;
5 %test
measure is ge and measure is FGT
However, by putting the two in quotes, I get nothing written to the log.
16 %macro test ;
17 %Let measure = FGT ;
18 %If "&measure" = "GE" %then %put measure is ge and measure is
&measure ;
19 %mEnd test ;
20 %test
Now, if I change the pass value to GS I get nothing written to the log.
31 %macro test ;
32 %Let measure = FGT ;
33 %If &measure = GS %then %put measure is ge and measure is &measure
;
34 %mEnd test ;
35 %test ;
Ah! I'm starting to get the picture. SAS allows the old FORTRAN comparison
operators
{EQ,NE,GT,LT,GE,LE}. So, let's look more closely at your code.
Suppose I replace GE with LE. Then I get no output.
36 %macro test ;
37 %Let measure = FGT ;
38 %If &measure = LE %then %put measure is ge and measure is &measure ;
39 %mEnd test ;
40 %test ;
So, SAS interpreted your code as
%If ( ( &measure = ) GE ) %then %put measure is ge and measure is &measure ;
So first it resolves ( &measure = ) to false (0) since FGT is not the same
as nothing.
41 %macro test ;
42 %Let measure = FGT ;
43 %If &measure = %then %put measure is ge and measure is &measure ;
44 %mEnd test ;
45 %test ;
Then SAS compares the false value (0) to a blank value and determines that
the 0 is greater than the blank (It is obviously not equal to a blank.).
26 %macro test ;
27 %Let measure = FGT ;
28 %If 0 GE %then %put measure is ge and measure is &measure ;
29 %mEnd test ;
30 %test ;
measure is ge and measure is FGT
Thanks, this was a good exercise.
Ed
Edward Heaton, Senior Systems Analyst,
Westat (An Employee-Owned Research Corporation),
1550 Research Boulevard, Room 2018, Rockville, MD 20850-3195
Voice: (301) 610-4818 Fax: (301) 294-3992
mailto:EdwardHeaton@westat.com http://www.westat.com
-----Original Message-----
From: Gabriel [mailto:gabo@ECON.BERKELEY.EDU]
Sent: Friday, July 27, 2001 4:41 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: problem with characters in macro %if expression
I have a problem using logical expressions with the macro language. I
have a line like this within a macro:
%IF &MEASURE=GE %then %put measure is ge and measure is &measure;
Now I know the macro variable MEASURE is set to FGT. When I run that
line with options symbolgen selected, I get the following inthe log
file:
SYMBOLGEN: Macro variable MEASURE resolves to FGT
SYMBOLGEN: Macro variable MEASURE resolves to FGT
measure is ge and measure is FGT
Why does SAS seem to think that &MEASURE=GE, when the output says
otherwise?
Thanks for the help!
Gabriel