Date: Mon, 29 Nov 2004 16:55:41 -0500
Reply-To: Ed Heaton <EdHeaton@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ed Heaton <EdHeaton@WESTAT.COM>
Subject: Re: Calculating with macro values (ie comparing to a # in if/the
n st atement)
Content-Type: text/plain
Venita;
You're working way too hard.
Macro vars are SAS code. Yeah, they are character, but so are 1,
5**3, and "29NOV2004"d. You say "These are not character, they're
numeric constants!" I say they are SAS code and SAS code consists of
characters (text). Consider the following.
%macro test( parm ) ;
%if &parm
%then %put Parm is a numeric constant that resolves to true. ;
%else %put Parm is a numeric constant that resolves to false. ;
%mEnd test ;
%test(1)
%test(0)
Now, 1 is SAS code - text - that represents a numeric constant. If it
were a character constant, SAS would complain with...
ERROR: A character operand was found in the %EVAL function or %IF
condition where a numeric operand is required. The condition
was: &parm
ERROR: The macro TEST will stop executing.
Ed
Edward Heaton, SAS Senior Systems Analyst,
Westat (An Employee-Owned Research Corporation),
1600 Research Boulevard, RW-3541, Rockville, MD 20850-3195
Voice: (301) 610-4818 Fax: (301) 610-5128
mailto:EdHeaton@Westat.com http://www.Westat.com
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of DePuy,
Venita
Sent: Monday, November 29, 2004 1:45 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Calculating with macro values (ie comparing to a # in if/then st
atement)
Hi all -
Hoping you can help me with an easy question that I just seem to be
missing -
I need to use a macro variable in some if/then calculations . .
ie
%if &numzeros ne 0 %then %do . . . . . %end;
%if Probt le &alpha %then %do . . . %end;
You get the idea.
The obvious issue being that macro vars are character. I'm just not
seeing a simple way to get them to numeric.
Trying a input statement gave me an error (although it could be just
me?)
I've tried %eval statements, with no luck (some error about the
operand not being present I think?)
One solution I've found is %if (%substr(&numzeros,1,1) ne 0) %then
%do . . . because numzeros is an integer, so if the first digit is zero,
it's zero . . but I know that's not the best way.
I've got several different versions of this in the program I'm
writing (ie comparing a macro variable to a number) so thought the most
efficient method would be to ask you all what I'm not seeing . . .
Thanks much!
Venita