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 ) ;
%then %put Parm is a numeric constant that resolves to true. ;
%else %put Parm is a numeric constant that resolves to false. ;
%mEnd test ;
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
ERROR: The macro TEST will stop executing.
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
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of DePuy,
Sent: Monday, November 29, 2004 1:45 PM
Subject: Calculating with macro values (ie comparing to a # in if/then st
Hi all -
Hoping you can help me with an easy question that I just seem to be
I need to use a macro variable in some if/then calculations . .
%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
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 . . .