LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2008, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 20 Jun 2008 06:35:05 -0500
Reply-To:     "data _null_," <datanull@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "data _null_," <datanull@GMAIL.COM>
Subject:      Re: Checking a macro keyword parameter for white space
Comments: To: Talbot Michael Katz <topkatz@msn.com>
In-Reply-To:  <200806192213.m5JArWZM027816@malibu.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1

I think using SUPERQ is a good method...

9 %macro cw1(vl=); 10 %if %SUPERQ(vl) eq %then %put NOTE: white!; 11 %else %put NOTE: dark!; 12 %mend cw1; 13 %cw1(vl=%nrstr( )); NOTE: white! 14 %cw1(); NOTE: white! 15 %cw1(vl=%str( )); NOTE: white! 16 %cw1(vl=a); NOTE: dark!

There was a thread a while back similar to this. Chang Chung has put gathered a number of very good examples and tests that I think he can pass along to you.

On 6/19/08, Talbot Michael Katz <topkatz@msn.com> 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" >


Back to: Top of message | Previous page | Main SAS-L page