Date: Fri, 20 Jun 2008 01:33:19 -0700
Reply-To: karma <dorjetarap@GOOGLEMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: karma <dorjetarap@GOOGLEMAIL.COM>
Organization: http://groups.google.com
Subject: Re: Checking a macro keyword parameter for white space
Content-Type: text/plain; charset=ISO-8859-1
Hi
No need to quote the macro variable, the standard way works quite
fine.
%macro test(val);
%if &val = %then %put >>> White!;
%else %put >>> Dark!;
%mend;
%test()
>>> White!
%test(%str( ))
>>> White!
%test(a)
>>> Dark!
Talbot Michael Katz wrote:
> Hi.
>
> I have a macro with a keyword parameter. If the parameter is blank, I
> want to trap it and give it a default value. I'd like to extend the idea
> of blank to cover any white space. Thus the following is not good enough:
>
> 400 %macro cw1(vl=) ;
> 401
> 402 %let vli = &vl. ;
> 403
> 404 %if "&vli." = "%str()" %then %do ;
> 405 %put white! ;
> 406 %end ;
> 407 %else %do ;
> 408 %put dark! ;
> 409 %end ;
> 410
> 411 %mend cw1 ;
> 412
> 413
> 414
> 415
> 416 %cw1 ;
> white!
> 417
> 418
> 419 %cw1() ;
> white!
> 420
> 421
> 422 %cw1(vl=) ;
> white!
> 423
> 424
> 425 %cw1(vl=%str()) ;
> white!
> 426
> 427
> 428 %cw1(vl=%str( )) ;
> dark!
>
>
> Okay, let me try to use %cmpres:
>
>
> 377 %macro cw4(vl=) ;
> 378
> 379 %let vli = &vl. ;
> 380
> 381 %if "&vli." = "%str()" or "%cmpres(&vli.))" = "%
> str()" or
> 381! "%cmpres(&vli.))" = "%str( )" %then %do ;
> 382 %put white! ;
> 383 %end ;
> 384 %else %do ;
> 385 %put dark! ;
> 386 %end ;
> 387
> 388 %mend cw4 ;
>
> 389
> 390 %cw4 ;
> white!
>
> 391
> 392 %cw4() ;
> white!
> 393
> 394 %cw4(vl=) ;
> white!
> 395
> 396 %cw4(vl=%str()) ;
> white!
> 397
> 398 %cw4(vl=%str( )) ;
> dark!
>
>
>
> That doesn't work any better! Plus it's kind of disturbing that using %
> cmpres on %str( ) is not equal to either %str() or %str( ).
>
> How about %sysfunc(compress())?
>
>
>
> 430 %macro cwt(vl=) ;
> 431
> 432 %let vli = &vl. ;
> 433
> 434 %if "&vli." = "%str()" or "%sysfunc(compress
> (&vli.))" = "%str()" %then
> 434! %do ;
> 435 %put white! ;
> 436 %end ;
> 437 %else %do ;
> 438 %put dark! ;
> 439 %end ;
> 440
> 441 %mend cwt ;
> 442
> 443
> 444 %cwt ;
> ERROR: The function COMPRESS referenced by the %SYSFUNC or %QSYSFUNC macro
> function has too few
> arguments.
> white!
> 445
> 446
> 447 %cwt() ;
> ERROR: The function COMPRESS referenced by the %SYSFUNC or %QSYSFUNC macro
> function has too few
> arguments.
> white!
> 448
> 449
> 450 %cwt(vl=) ;
> ERROR: The function COMPRESS referenced by the %SYSFUNC or %QSYSFUNC macro
> function has too few
> arguments.
> white!
> 451
> 452
> 453 %cwt(vl=%str()) ;
> white!
> 454
> 455
> 456 %cwt(vl=%str( )) ;
> white!
>
>
>
> It gets the right results, but generates ugly error messages. I could get
> this to work if I used an %else %if clause:
>
>
>
> 310 %macro cw2(vl=) ;
> 311
> 312 %let vli = &vl. ;
> 313
> 314 %if "&vli." = "%str()" %then %do ;
> 315 %put white! ;
> 316 %end ;
> 317 %else %if "%sysfunc(compress(&vli.))" = "%str()" %then %
> do ;
> 318 %put whi2e! ;
> 319 %end ;
> 320 %else %do ;
> 321 %put dark! ;
> 322 %end ;
> 323
> 324 %mend cw2 ;
> 325
> 326
> 327
> 328
> 329 %cw2 ;
> white!
>
> 330
> 331 %cw2() ;
> white!
> 332
> 333 %cw2(vl=) ;
> white!
> 334
> 335 %cw2(vl=%str( )) ;
> whi2e!
> 336
> 337 %cw2(vl=%str( )) ;
> whi2e!
>
>
>
> I know this is kind of anal retentive, because who in the world would ever
> specify a keyword parameter as %str( ), but is there a better / simpler
> way to trap white space parameter values?
>
> Thanks!
>
>
> -- TMK --
> "The Macro Klutz"
|