Date: Thu, 31 Jan 2008 16:59:40 -0500
Reply-To: Scott Bucher <ir.bucher@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Scott Bucher <ir.bucher@GMAIL.COM>
Subject: checking for missing parameters
Content-Type: text/plain; charset=ISO-8859-1
Hi All,
I have been reviewing a few macros presented in conference papers, and
noticed the relatively simple act of checking for missing parameters has
been done a number of different ways. Below, I have presented five different
methods. I am wondering what is generally the most effective method, (which
may not be presented above)?
%macro test(x = );
%if &x = %then %put ERROR: x is missing (method 1);
%if &x = %str() %then %put ERROR: x is missing (method 2);
%if %length(&x) = 0 %then %put ERROR: x is missing (method 3);
%if %superq(x) = %then %put ERROR: x is missing (method 4);
%if %superq(x) = %str() %then %put ERROR: x is missing (method 5);
%if %length(%sysfunc(compress(&x, ' '))) = 0 %then %put ERROR: x is
missing (method 6);
%mend test;
%test();
As far as I can tell, #2 and #3 are equivalent, both being attempts to avoid
the confusion of the ostensibly unbalanced (=) found in #1; or is there some
practical distinction between using %str v. %length in this context?
However, method 4 (using %superq) would generally be the safest and simplest
method, as it would execute properly if the value of the parameter had
special characters. Method #5 combines the virtues of being effective and
avoiding conversion. I'm not sure what #6 achieves beyond #3.
I hope this is not hair-splitting, but I expect I may be missing some subtle
(probably glaringly obvious for others), non-trival differences. My goal is
to understand the best approach so I can consistently apply one method (i.e.
#5) across my macros.
Thanks,
Scott Bucher
Associate Education Analyst
NYC Dept. of Education