Date: Fri, 31 Mar 2000 15:25:08 -0500
Reply-To: Richard DeVenezia <radevenz@IX.NETCOM.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Richard DeVenezia <radevenz@IX.NETCOM.COM>
Organization: MindSpring Enterprises
Subject: Re: checking null string in macro
Jun:
Try using the macro function
%LENGTH(&RAND)
If the value of RAND is allowed to contain macro'ey type values (%'s and
&'s) use
%LENGTH(%SUPERQ(RAND))
If the value of RAND can contain only blanks (.e.g %let RAND = %str ( );)
then %LENGTH will return non-zero. In that case use:
%if (&MACROVAR ne %str()) %then ...
(or %SUPERQ(MACROVAR) ne %str())
Also,
when using macro to conditionally generate a statement for compilation in a
PROC or DATA step be sure to end the 'concept' will two semi-colons. This
is necessary when NOT using %do %end blocks.
The first semi-colon ends the macro statement
The second semi-colon ends the generated statement
example:
%if (&rand ne %str()) %then random &rand;; %* note the double-semi;
%if (&rand ne %str()) %then %do;
random &rand;
%end; %* no need for a double-semi when using %do %end blocks;
Richard
"Jun Yan" <jyan@stat.wisc.edu> wrote in message
news:Pine.LNX.3.96L.1000331112645.1523B-100000@istat09.stat.wisc.edu...
> Hi,
>
> I am trying to creat a simple macro like this,
>
> %macro testing(dat, mod, clas, rand)
> proc mixed data = &dat;
> class &clas;
> model &mod;
> %if length(&rand)=0 %then random &rand;
> %mend;
>
> I want the random statement only when &rand is not null, but
> length(&rand) seems not working. Is there an elegant way to do this?
>
> Jun