Date: Tue, 23 Dec 2003 10:02:46 -0500
Reply-To: "Fehd, Ronald J. (PHPPO)" <rjf2@CDC.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Fehd, Ronald J. (PHPPO)" <rjf2@CDC.GOV>
Subject: Re: Bad %IF condition
Content-Type: text/plain; charset="us-ascii"
> From: Kevin Roland Viel [mailto:kviel@EMORY.EDU]
> Both replies, for which I kindly thank the authors, hint that
> my comparison is in error which could be corrected by using
> %let match=;
> Ron wrote:
> > your comparison to $char1. fails.
> Does this imply the the macro variable (MV) MATCH has an
> ultimate different format? Further, SAS does not accept a
> comparison between say $char1. and $char2.?
uh, I see that my use of SAS-ese in explaining macro-ese
has added more confusion than clarity.
macro variables do not have SAS-ese formats associated with them.
They are completely
and only character.
Their length varies from 0 to (a large number like) 32K.
> My values should be " " and "somthing else".
if those are your only two values
then I would suggest something logically clear like (0,1)
also known as boolean (zero,one)
> It is strange that this is rejected as needed to be numeric,
as a condition it has to eventually yield
or (greater than or equal to) one
> though it seems this would be the message SAS would give
> if the MV MATCH did not exist.
uh, not exist(Match) means it is not in the macro symbol table
of whatever scope (referencing environment in (global,local))
that is different from Match having a null value
whose %length(Match) is zero.
> Does this mean that I should be concerned with the format
> (length) of the values? If so, I need to check all of my code!
Well, if that's the excuse you need to reread and polish your code
then I'll vote for it.
in the meantime
consider that macro variables generally fall into three sets:
* numbers, hopefully integers
My mnemonic for testing character mVars is to dQuote them:
thus my original suggestion of:
%If "&mVar." eq "" %then ...
I find the test of null without dQuotes
generates a "non sequitur" warning in my brain
%If &mVar. eq %then ...
"Something important just happened there;
Loop: ... I better reread it.
how many times you reread the statement
depends on your tolerance of ClueLessNess.
Good Code isn't necessarily (easily) Readable Code
which is why I prefer to use boolean
or integers for conditions:
%Let Testing = 0;
*Let Testing = 1;
%If &Testing. %then ...
note that Nobs can be zero or greater than zero
the above style will still work
%Let Nobs = %Nobs(data = Work.MostRecent);
%If &Nobs. %then ...
and last but not least
a v9 feature:
When is a string not a string?
When it is a condition.
%Let Where = 1;
%Let Where = SomeVar eq 'A';
(where = (&Where.))
in v8 I had these parameters
%Let Where = .;
%Let Where = SomeVar eq 'A';
%Let Value = B;
%Let Where = SomeVar eq "&Value.";
%If "&Where." ne "." %then
where = (&Where.);
Ron Fehd the macro maven CDC Atlanta GA USA RJF2@cdc.gov
do not fold, spindle, or mutilate -- IBM punch card
... the format of the macro variable ;-)